Matt Rubin 4ff4757744 Merge pull request #30 from mattrubin/modernize
Modernize for Xcode 16 and Swift 6
2024-12-10 17:02:55 -05:00
2024-12-09 23:50:14 -05:00
2024-12-09 23:03:25 -05:00
2024-12-08 23:38:05 -05:00
2024-12-09 23:16:31 -05:00
2024-12-08 22:29:34 -05:00
2024-12-09 23:16:31 -05:00

Identifier

Unique, strongly-typed identifiers in Swift.

Xcode CI status SPM CI status Code Coverage Swift 6.0 Platforms: iOS, macOS, tvOS, visionOS, watchOS, Linux MIT License

Identifier is a generic struct backed by a UUID, which can be specialized for the model type it identifies and provides unique, decentralized identity in a value type. It is Equatable, Hashable, Sendable, and Codable, serializing to a simple UUID string.

Instead of using string identifiers in your models:

struct Comment: Equatable, Codable {
    let postID: String
    let authorID: String
    let text: String
    let date: Date
}

You can use typed identifiers, which help ensure an ID for a model of one type is never accidentally used in place of another:

struct Comment: Equatable, Codable {
    let postID: Identifier<Post>
    let authorID: Identifier<User>
    let text: String
    let date: Date
}

Installation

SPM

Add the following line to the dependencies section of your package manifest:

.package(url: "https://github.com/mattrubin/Identifier.git", from: "1.1.0"),

Then add "Identifier" to the dependencies array of any target which should be linked with this library.

License

Identifier is released under the MIT License.

S
Description
🧬 Unique, strongly-typed identifiers in Swift.
Readme 152 KiB
Languages
Swift 100%