Skip to content

Commit 6b14c2a

Browse files
author
Kyle Macomber
authored
[Docs] Clarifies Identifiable requirements (#31472)
[SR-12528](https://bugs.swift.org/browse/SR-12528) rdar://62201744
1 parent b121ce9 commit 6b14c2a

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

stdlib/public/core/Identifiable.swift

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,42 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

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.
1441
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1542
public protocol Identifiable {
1643

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.
1846
associatedtype ID: Hashable
1947

20-
/// The stable identity of the entity associated with `self`.
48+
/// The stable identity of the entity associated with this instance.
2149
var id: ID { get }
2250
}
2351

0 commit comments

Comments
 (0)