Identifier
is a Bytes
-backed, globally unique identifier. It is commonly used as a model identifier and it can help one conform to Swift's Identifiable
protocol.
struct Todo: Hashable, Identifiable {
let id: Identifier
let title: String
let isCompleted: Bool
}
extension Todo {
init(title: String) {
id = Identifier() // New, unique identifier
self.title = title
isCompleted = false
}
}
To use Identifier
with the Swift Package Manager, add a dependency to your Package.swift
file:
let package = Package(
dependencies: [
.package(
name: "Identifier",
url: "https://github.com/shareup/identifier-apple.git",
from: "3.0.0"
)
]
)