|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 |
| -/// A class of types whose instances hold the value of an entity with stable identity. |
| 13 | +/// A class of types whose instances hold the value of an entity with stable |
| 14 | +/// identity. |
| 15 | +/// |
| 16 | +/// Use the `Identifiable` protocol to provide a stable notion of identity to a |
| 17 | +/// class or value type. For example, you could define a `User` type with an `id` |
| 18 | +/// property that is stable across your app and your app's database storage. |
| 19 | +/// You could use the `id` property to identify a particular user even if other |
| 20 | +/// data fields change, such as the user's name. |
| 21 | +/// |
| 22 | +/// `Identifiable` leaves the duration and scope of the identity unspecified. |
| 23 | +/// Identities could be any of the following: |
| 24 | +/// |
| 25 | +/// - Guaranteed always unique (e.g. UUIDs). |
| 26 | +/// - Persistently unique per environment (e.g. database record keys). |
| 27 | +/// - Unique for the lifetime of a process (e.g. global incrementing integers). |
| 28 | +/// - Unique for the lifetime of an object (e.g. object identifiers). |
| 29 | +/// - Unique within the current collection (e.g. collection index). |
| 30 | +/// |
| 31 | +/// It is up to both the conformer and the receiver of the protocol to document |
| 32 | +/// the nature of the identity. |
| 33 | +/// |
| 34 | +/// Conforming to the Identifiable Protocol |
| 35 | +/// ======================================= |
| 36 | +/// |
| 37 | +/// `Identifiable` provides a default implementation for class types (using |
| 38 | +/// `ObjectIdentifier`), which is only guaranteed to remain unique for the |
| 39 | +/// lifetime of an object. If an object has a stronger notion of identity, it |
| 40 | +/// may be appropriate to provide a custom implementation. |
14 | 41 | @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
15 | 42 | public protocol Identifiable {
|
16 | 43 |
|
17 |
| - /// A type representing the stable identity of the entity associated with `self`. |
| 44 | + /// A type representing the stable identity of the entity associated with |
| 45 | + /// an instance. |
18 | 46 | associatedtype ID: Hashable
|
19 | 47 |
|
20 |
| - /// The stable identity of the entity associated with `self`. |
| 48 | + /// The stable identity of the entity associated with this instance. |
21 | 49 | var id: ID { get }
|
22 | 50 | }
|
23 | 51 |
|
|
0 commit comments