Skip to content

Instantly share code, notes, and snippets.

@haifengkao
Created January 8, 2021 10:04
Show Gist options
  • Save haifengkao/79e93181705451b82e15ddefc0e0c104 to your computer and use it in GitHub Desktop.
Save haifengkao/79e93181705451b82e15ddefc0e0c104 to your computer and use it in GitHub Desktop.
TaggedWeakWillCrashIfPutToEnum
public class TaggedWeak<T: AnyObject, Hash: Hashable>: Hashable {
public static func == (lhs: TaggedWeak<T, Hash>, rhs: TaggedWeak<T, Hash>) -> Bool {
lhs.hash == rhs.hash
}
public func hash(into hasher: inout Hasher) {
hasher.combine(hash)
}
public weak var value: T?
let hash: Hash
public init(hash: Hash, _ value: T?) {
self.value = value
self.hash = hash
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment