Skip to content

Instantly share code, notes, and snippets.

@anandabits
Last active June 20, 2022 03:23
Show Gist options
  • Save anandabits/6efb863d933257c0b66e5beb02a55b59 to your computer and use it in GitHub Desktop.
Save anandabits/6efb863d933257c0b66e5beb02a55b59 to your computer and use it in GitHub Desktop.
Implementation of the Swift Identifiable protocol
/// A class of types whose instances hold the value of an entity with stable identity.
protocol Identifiable {
/// A type representing the stable identity of the entity associated with `self`.
associatedtype ID: Hashable
/// The stable identity of the entity associated with `self`.
var id: ID { get }
}
extension Identifiable where Self: AnyObject {
var id: ObjectIdentifier {
return ObjectIdentifier(self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment