Build an app with SwiftData

RSS for tag

Discuss the WWDC23 Build an app with SwiftData

Posts under wwdc2023-10154 tag

1 Post

Post

Replies

Boosts

Views

Activity

@Attribute 'unique' and complex keys
The 'unique' attribute is a really nice feature, BUT. In some of my apps, the unique identifier for an object is a combination of multiple attributes. (Example: a book title is not unique, but a combination of book title and author list is.) How do I model this with SwiftData? I cannot use @Attribute(.unique) on either the title OR the author list, but I want SwiftData to provide the same "insert or update" logic. Is this possible?
5
4
2.7k
Sep ’25