You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above `Article` identifier is now backed by a `UUID` instead of a `String`.
34
+
31
35
## Conveniences built-in
32
36
33
-
Identity makes identifiers more type-safe, while still offering several conveniences to help reduce verbosity. For example, if an `Identifier` is backed by a raw value type that can be expressed by a `String` literal, so can the identifier:
37
+
Even though Identity is focused on type safety, it still offers several conveniences to help reduce verbosity. For example, if an `Identifier` is backed by a raw value type that can be expressed by a `String` literal, so can the identifier:
34
38
35
39
```swift
36
40
let user =User(id: "johnsundell", name: "John Sundell")
37
41
```
38
42
39
-
The same is also true for identifiers that are backend by raw value type that can be expressed by `Int` literals:
43
+
The same is also true for identifiers that are backend by a raw value type that can be expressed by `Int` literals:
40
44
41
45
```swift
42
46
let tag =Tag(id: 7, name: "swift")
@@ -46,13 +50,13 @@ let tag = Tag(id: 7, name: "swift")
46
50
47
51
## Type safety
48
52
49
-
So how exactly does Identity make identifiers more type-safe? First, when using Identity, it no longer becomes possible to accidentally pass an identifier for one type to an API that accepts an identifier for another type. For example, this code won't compile:
53
+
So how exactly does Identity make identifiers more type-safe? First, when using Identity, it no longer becomes possible to accidentally pass an identifier for one type to an API that accepts an identifier for another type. For example, this code won't compile when using Identity:
50
54
51
55
```swift
52
56
articleManager.article(withID: user.id)
53
57
```
54
58
55
-
The compiler will give us an error above, since we're trying to pass an `Identifier<User>` value to a method that accepts an `Identifier<Article>`, giving us much stronger type safety.
59
+
The compiler will give us an error above, since we're trying to pass an `Identifier<User>` value to a method that accepts an `Identifier<Article>` - giving us much stronger type safety than when using plain values, like `String` or `Int`, as identifiers.
56
60
57
61
Identity also makes it impossible to accidentially declare `id` properties of the wrong type. So the following won't compile either:
58
62
@@ -66,22 +70,16 @@ The reason the above code will fail to compile is because `Identifiable` require
66
70
67
71
## Installation
68
72
69
-
Since **Codextended** is implemented within a single file, the easiest way to use it is to simply drag and drop it into your Xcode project.
73
+
Since Identity is implemented within a single file, the easiest way to use it is to simply drag and drop it into your Xcode project.
70
74
71
-
But if you wish to use a dependency manager, you can either use the [Swift Package Manager](https://github.com/apple/swift-package-manager) by declaring **Codextended** as a dependency in your `Package.swift` file:
75
+
But if you wish to use a dependency manager, you can either use the [Swift Package Manager](https://github.com/apple/swift-package-manager) by declaring Identity as a dependency in your `Package.swift` file:
0 commit comments