Last active
June 20, 2022 03:23
-
-
Save anandabits/6efb863d933257c0b66e5beb02a55b59 to your computer and use it in GitHub Desktop.
Implementation of the Swift Identifiable protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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