Skip to content

Instantly share code, notes, and snippets.

@haifengkao
Created January 8, 2021 10:03
Show Gist options
  • Save haifengkao/a15d3a02d8a1101ad91303a75b8f66d4 to your computer and use it in GitHub Desktop.
Save haifengkao/a15d3a02d8a1101ad91303a75b8f66d4 to your computer and use it in GitHub Desktop.
TaggedWeakCanBePutToEnum.swift
public struct 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