Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

Reply to WWDC25 Metal & game technologies group lab
If Getting into visionOS and metal for creating games - Is there any tips or optimal apis/framework/tools that you would recommend? Easiest way to start on visionOS is with RealityKit. The GameController framework supports lots of controllers for different types of games. 200GB of Background Assets available for content rich games. Are there standard methods of achieving synchronization of state between players (specifically using VisionOS here) or is it a roll-your-own situation? For synchronizing objects in a Shared spatial environment, consider using TableTopKit, which is compatible with GKMatch in the GameKit framework. If you’re using RealityKit, you can use SynchronizationService to coordinate shared physically simulated objects. We also recommend the WWDC session: Share visionOS experiences with nearby people. Which official Metal docs or sample projects best support teams moving a CPU-centric CAD kernel to GPU-accelerated workflows on Apple Silicon The Performing Calculations on a GPU sample code show
Topic: Graphics & Games SubTopic: Metal Tags:
Jul ’25
Reply to What is going on with transformable
@Jerome_Donfack There are two main requirements to use transformer in SwiftData: The type returned by transformedValueClass needs to correspond to the type you declare in the model, so it needs to be changed to NSArray.self transformedValue can only be encoded as NSData, and in CoreData, we can encode into any supported type, such as NSNumber, NSString Override class func transformedValueClass() -> AnyClass { Return NSArray.self // change to NSArray } BTW: If it is not to be compatible with your other custom data, SwiftData will use the built-in transaformer to encode [String] without using transformable
Jul ’25
What is going on with transformable
Hi, I keep trying to use transformable to store an array of strings with SwiftData, and I can see that it is activating the transformer, but it keeps saying that I am still using NSArray instead of NSData. *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = category; desired type = NSData; given type = Swift.__SwiftDeferredNSArray; value = ( yo, gurt ).' terminating due to uncaught exception of type NSException CoreSimulator 1010.10 - Device: iPhone 16 18.0 (6879535B-3174-4025-AD37-ED06E60291AD) - Runtime: iOS 18.0 (22A3351) - DeviceType: iPhone 16 Message from debugger: killed @Model class MyModel: Identifiable, Equatable { @Attribute(.transformable(by: StringArrayTransformer.self)) var category: [String]? @Attribute(.transformable(by: StringArrayTransformer.self)) var amenities: [String]? var image: String? var parentChunck: HenricoPostDataChunk_V1? init(category: [String]?, amenities: [String]?) { self.category =
3
0
207
Jul ’25
What is going on with transformable
Hi, I keep trying to use transformable to store an array of strings with SwiftData, and I can see that it is activating the transformer, but it keeps saying that I am still using NSArray instead of NSData. *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = category; desired type = NSData; given type = Swift.__SwiftDeferredNSArray; value = ( yo, gurt ).' terminating due to uncaught exception of type NSException CoreSimulator 1010.10 - Device: iPhone 16 18.0 (6879535B-3174-4025-AD37-ED06E60291AD) - Runtime: iOS 18.0 (22A3351) - DeviceType: iPhone 16 Message from debugger: killed @Model class MyModel: Identifiable, Equatable { @Attribute(.transformable(by: StringArrayTransformer.self)) var category: [String]? @Attribute(.transformable(by: StringArrayTransformer.self)) var amenities: [String]? var image: String? var parentChunck: MyModelDataChunk_V1? init(category: [String]?, amenities: [String]?) { self.category = cat
1
0
147
Jul ’25
Does Core Spotlight work with document-based apps?
I have a SwiftUI document-based app that for the sake of this discussion stores accounting information: chart of accounts, transactions, etc. Each document is backed by a SwiftData DB. I'd like to incorporate search into the app so that users can find transactions matching certain criteria, so I went to Core Spotlight. Indexing & search within the app seem to work well. The issue is that Spotlight APIs appear to be App based & not Document based. I can't find a way to separate Spotlight data by document. I've tried having each document maintain a UUID as a document-specific identifier and include the identifier in every CSSearchableItem. When performing a query I filter the results with CSUserQueryContext.filterQueries that filter by the document identifier. That works to limit results to the specific file for search operations. Index updates via CSSearchableIndexDelegate.reindex* methods seem to be App-centric. A user may have file #1 open, but the delegate is being asked to update CSSearcha
7
0
255
Jul ’25
Complex Swift Data Relationships...
I am struggling with exactly how to set up SwiftData relationships, beyond the single relationship model... Let's say I have a school. Each school offers a set of classes. Each class is taught by one teacher and attended by several students. Teachers may teach more than one class, but only at one school. Similarly students may attend more than one class, but only at one school. Classes themselves may be offered at more than one school. Can someone create a class for School, SchoolClass, Teacher, and Student with id, name, and relationships... I have tried it unsuccessfully about 10 different ways at this point. My most recent is below... I am struggling getting beyond a school listing in the app, and I'll cross that bridge next. I am just wondering if all the trouble I am having is because I am not smart with the class definitions. And wondering if this is to complex for SwiftData and CoreData is the requirement. This is not a real app, just my way of really trying
Topic: Design SubTopic: General Tags:
6
0
792
Jul ’25
Reply to Does Core Spotlight work with document-based apps?
Thank you again for the thoughtful response. This is the high level solution I've ended up with. To recap: This is a SwiftUI document-based app: DocumentGroup backed by SwiftData. A user will typically have only a few of these files. A file will typically have only a few thousand indexed records. Search is required for in-app use only; system-wide search is not. The application maintains a single search index. When the app launches it deletes all items from the search index. This keeps the search index clean in the case of renamed, deleted or seldom used files. A document uses the domainIdentifier search attribute set to its URL to tag all of its searchable items. When a document is opened it deletes all of its searchable items using the domainIdentifier to scope the operation. It then adds all of its searchableItems to the index. The document adds, deletes & updates its searchable items while it is open. When a document's URL changes it updates the domainIdentifier of its searchable items. In-ap
Topic: App & System Services SubTopic: General Tags:
Jul ’25
Reply to Complex Swift Data Relationships...
Another few small refinements - school delete rules set up I think import Foundation import SwiftData // Define School // Each School will offer a list of [Schoolclass] // Each Schoolclass will have one Teacher and a list of [Student] // Each Teacher may teach multiple classes, but only at one unique school // Each Student will attend multiple classes but only at one unique school // Bonus!! Start with the assumption that each SchoolClass instance is unique and only offered in one school, but want to expand so that a particular SchoolClass may be offered at more than one school, but have unique Teacher and [Student] for that class at each school @Model class School: Identifiable { var id: UUID = UUID() var name: String var mascot: String @Relationship(deleteRule: .cascade) var schoolClasses: [SchoolClass] // If a school is deleted, delete the classes associated with it, but leave the students and teachers all with an empty class list. // Every school that is created will have a class list, b
Topic: Design SubTopic: General Tags:
Jun ’25
Reply to Complex Swift Data Relationships...
Another day of refining this model gets me to the following code... Please see if my comments are correct, and if I am missing something... import Foundation import SwiftData // Define School // Each School will offer a list of [Schoolclass] // Each Schoolclass will have one Teacher and a list of [Student] // Each Teacher may teach multiple classes, but only at one unique school // Each Student will attend multiple classes but only at one unique school // Bonus!! Start with the assumption that each SchoolClass instance is unique and only offered in one school, but want to expand so that a particular SchoolClass may be offered at more than one school, but have unique Teacher and [Student] for that class at each school @Model class School: Identifiable { var id: UUID = UUID() var name: String var mascot: String var schoolClasses: [SchoolClass] // Every school that is created will have a class list, but it may be an empty list init (name: String, mascot: String = , schoolClasses: [SchoolClass] = []) { s
Topic: Design SubTopic: General Tags:
Jun ’25
Reply to Complex Swift Data Relationships...
Some will be easy to get like all teachers for a school but others will require a little more work. One important thing to remember is that you add relationships to define your models and how they relate and not for helping with some queries you might want to implement. That said, one further relationship to consider is between School and Student so that a student can only take classes that belongs to the school they are assigned to.
Topic: Design SubTopic: General Tags:
Jun ’25
Reply to Does Core Spotlight work with document-based apps?
filterQueries is actually being passed over and processed on the daemon side Excellent. The correct answer is to create a CSImportExtension. That extension point hands you the file you're indexing, side stepping the entire issue. Looking at the documentation for CSImportExtension it appears that this is for gathering & updating information about a file, not the items in the file. The extension only gets one CSSearchableItemAttributeSet that is for metadata about the file. An object that provides searchable attributes for file types that the app supports. Even if I wanted to misuse the API just to trigger a full reindex of the file contents, due to sandbox restrictions I don't think it would be possible to open an arbitrary file. The user would have to select the file in an Open dialog. My current solution is: When a document is opened start a Task that gathers all of the uniqueIdentifiers of the searchableItems for this file from the search index (using the contentURL to filter the results). Gather the mo
Topic: App & System Services SubTopic: General Tags:
Jun ’25
Reply to Complex Swift Data Relationships...
You haven't told us exactly what your issue is but something I spotted with your design that I don't think is correct is the relationship between Teacher and Student. As I see it your design will be simpler and more correct if you complete remove that relationship. A teacher holds (has) one or more classes A student attends (has) one or more classes So indirectly you have the relationship between Teacher and Student via the SchoolClass model. A bit unrelated but I prefer to use the @Relationship macro with the inverted argument for one of the relationship properties since it makes the code clearer for me (and it is also helpful for SwiftData)
Topic: Design SubTopic: General Tags:
Jun ’25
Type ReferenceWritableKeyPath does not conform to the 'Sendable' protocol
This is not a question but more of a hint where I was having trouble with. In my SwiftData App I wanted to move from Swift 5 to Swift 6, for that, as recommended, I stayed in Swift 5 language mode and set 'Strict Concurrency Checking' to 'Complete' within my build settings. It marked all the places where I was using predicates with the following warning: Type '' does not conform to the 'Sendable' protocol; this is an error in the Swift 6 language mode I had the same warnings for SortDescriptors. I spend quite some time searching the web and wrapping my head around how to solve that issue to be able to move to Swift 6. In the end I found this existing issue in the repository of the Swift Language https://github.com/swiftlang/swift/issues/68943. It says that this is not a warning that should be seen by the developer and in fact when turning Swift 6 language mode on those issues are not marked as errors. So if anyone is encountering this when trying to fix all issues while staying in Swift 5 language mo
3
0
1.1k
Jun ’25
Reply to WWDC25 Metal & game technologies group lab
If Getting into visionOS and metal for creating games - Is there any tips or optimal apis/framework/tools that you would recommend? Easiest way to start on visionOS is with RealityKit. The GameController framework supports lots of controllers for different types of games. 200GB of Background Assets available for content rich games. Are there standard methods of achieving synchronization of state between players (specifically using VisionOS here) or is it a roll-your-own situation? For synchronizing objects in a Shared spatial environment, consider using TableTopKit, which is compatible with GKMatch in the GameKit framework. If you’re using RealityKit, you can use SynchronizationService to coordinate shared physically simulated objects. We also recommend the WWDC session: Share visionOS experiences with nearby people. Which official Metal docs or sample projects best support teams moving a CPU-centric CAD kernel to GPU-accelerated workflows on Apple Silicon The Performing Calculations on a GPU sample code show
Topic: Graphics & Games SubTopic: Metal Tags:
Replies
Boosts
Views
Activity
Jul ’25
Reply to What is going on with transformable
@Jerome_Donfack There are two main requirements to use transformer in SwiftData: The type returned by transformedValueClass needs to correspond to the type you declare in the model, so it needs to be changed to NSArray.self transformedValue can only be encoded as NSData, and in CoreData, we can encode into any supported type, such as NSNumber, NSString Override class func transformedValueClass() -> AnyClass { Return NSArray.self // change to NSArray } BTW: If it is not to be compatible with your other custom data, SwiftData will use the built-in transaformer to encode [String] without using transformable
Replies
Boosts
Views
Activity
Jul ’25
What is going on with transformable
Hi, I keep trying to use transformable to store an array of strings with SwiftData, and I can see that it is activating the transformer, but it keeps saying that I am still using NSArray instead of NSData. *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = category; desired type = NSData; given type = Swift.__SwiftDeferredNSArray; value = ( yo, gurt ).' terminating due to uncaught exception of type NSException CoreSimulator 1010.10 - Device: iPhone 16 18.0 (6879535B-3174-4025-AD37-ED06E60291AD) - Runtime: iOS 18.0 (22A3351) - DeviceType: iPhone 16 Message from debugger: killed @Model class MyModel: Identifiable, Equatable { @Attribute(.transformable(by: StringArrayTransformer.self)) var category: [String]? @Attribute(.transformable(by: StringArrayTransformer.self)) var amenities: [String]? var image: String? var parentChunck: HenricoPostDataChunk_V1? init(category: [String]?, amenities: [String]?) { self.category =
Replies
3
Boosts
0
Views
207
Activity
Jul ’25
Reply to Is it possible to animate the accessibility frame on iOS and macOS?
I am working with an NSAccessibilityElement that corresponds to a custom UI element that doesn't inherit from NSView or one of the other accessibility-enabled AppKit classes. I would like to update its accessibility frame as the UI element moves on the screen (so, during the animation itself), while VoiceOver is focused on this element.
Replies
Boosts
Views
Activity
Jul ’25
What is going on with transformable
Hi, I keep trying to use transformable to store an array of strings with SwiftData, and I can see that it is activating the transformer, but it keeps saying that I am still using NSArray instead of NSData. *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = category; desired type = NSData; given type = Swift.__SwiftDeferredNSArray; value = ( yo, gurt ).' terminating due to uncaught exception of type NSException CoreSimulator 1010.10 - Device: iPhone 16 18.0 (6879535B-3174-4025-AD37-ED06E60291AD) - Runtime: iOS 18.0 (22A3351) - DeviceType: iPhone 16 Message from debugger: killed @Model class MyModel: Identifiable, Equatable { @Attribute(.transformable(by: StringArrayTransformer.self)) var category: [String]? @Attribute(.transformable(by: StringArrayTransformer.self)) var amenities: [String]? var image: String? var parentChunck: MyModelDataChunk_V1? init(category: [String]?, amenities: [String]?) { self.category = cat
Replies
1
Boosts
0
Views
147
Activity
Jul ’25
Does Core Spotlight work with document-based apps?
I have a SwiftUI document-based app that for the sake of this discussion stores accounting information: chart of accounts, transactions, etc. Each document is backed by a SwiftData DB. I'd like to incorporate search into the app so that users can find transactions matching certain criteria, so I went to Core Spotlight. Indexing & search within the app seem to work well. The issue is that Spotlight APIs appear to be App based & not Document based. I can't find a way to separate Spotlight data by document. I've tried having each document maintain a UUID as a document-specific identifier and include the identifier in every CSSearchableItem. When performing a query I filter the results with CSUserQueryContext.filterQueries that filter by the document identifier. That works to limit results to the specific file for search operations. Index updates via CSSearchableIndexDelegate.reindex* methods seem to be App-centric. A user may have file #1 open, but the delegate is being asked to update CSSearcha
Replies
7
Boosts
0
Views
255
Activity
Jul ’25
Complex Swift Data Relationships...
I am struggling with exactly how to set up SwiftData relationships, beyond the single relationship model... Let's say I have a school. Each school offers a set of classes. Each class is taught by one teacher and attended by several students. Teachers may teach more than one class, but only at one school. Similarly students may attend more than one class, but only at one school. Classes themselves may be offered at more than one school. Can someone create a class for School, SchoolClass, Teacher, and Student with id, name, and relationships... I have tried it unsuccessfully about 10 different ways at this point. My most recent is below... I am struggling getting beyond a school listing in the app, and I'll cross that bridge next. I am just wondering if all the trouble I am having is because I am not smart with the class definitions. And wondering if this is to complex for SwiftData and CoreData is the requirement. This is not a real app, just my way of really trying
Topic: Design SubTopic: General Tags:
Replies
6
Boosts
0
Views
792
Activity
Jul ’25
Reply to Does Core Spotlight work with document-based apps?
Thank you again for the thoughtful response. This is the high level solution I've ended up with. To recap: This is a SwiftUI document-based app: DocumentGroup backed by SwiftData. A user will typically have only a few of these files. A file will typically have only a few thousand indexed records. Search is required for in-app use only; system-wide search is not. The application maintains a single search index. When the app launches it deletes all items from the search index. This keeps the search index clean in the case of renamed, deleted or seldom used files. A document uses the domainIdentifier search attribute set to its URL to tag all of its searchable items. When a document is opened it deletes all of its searchable items using the domainIdentifier to scope the operation. It then adds all of its searchableItems to the index. The document adds, deletes & updates its searchable items while it is open. When a document's URL changes it updates the domainIdentifier of its searchable items. In-ap
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jul ’25
Reply to Complex Swift Data Relationships...
Another few small refinements - school delete rules set up I think import Foundation import SwiftData // Define School // Each School will offer a list of [Schoolclass] // Each Schoolclass will have one Teacher and a list of [Student] // Each Teacher may teach multiple classes, but only at one unique school // Each Student will attend multiple classes but only at one unique school // Bonus!! Start with the assumption that each SchoolClass instance is unique and only offered in one school, but want to expand so that a particular SchoolClass may be offered at more than one school, but have unique Teacher and [Student] for that class at each school @Model class School: Identifiable { var id: UUID = UUID() var name: String var mascot: String @Relationship(deleteRule: .cascade) var schoolClasses: [SchoolClass] // If a school is deleted, delete the classes associated with it, but leave the students and teachers all with an empty class list. // Every school that is created will have a class list, b
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’25
Reply to Complex Swift Data Relationships...
Another day of refining this model gets me to the following code... Please see if my comments are correct, and if I am missing something... import Foundation import SwiftData // Define School // Each School will offer a list of [Schoolclass] // Each Schoolclass will have one Teacher and a list of [Student] // Each Teacher may teach multiple classes, but only at one unique school // Each Student will attend multiple classes but only at one unique school // Bonus!! Start with the assumption that each SchoolClass instance is unique and only offered in one school, but want to expand so that a particular SchoolClass may be offered at more than one school, but have unique Teacher and [Student] for that class at each school @Model class School: Identifiable { var id: UUID = UUID() var name: String var mascot: String var schoolClasses: [SchoolClass] // Every school that is created will have a class list, but it may be an empty list init (name: String, mascot: String = , schoolClasses: [SchoolClass] = []) { s
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’25
Reply to Complex Swift Data Relationships...
Some will be easy to get like all teachers for a school but others will require a little more work. One important thing to remember is that you add relationships to define your models and how they relate and not for helping with some queries you might want to implement. That said, one further relationship to consider is between School and Student so that a student can only take classes that belongs to the school they are assigned to.
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’25
Reply to Does Core Spotlight work with document-based apps?
filterQueries is actually being passed over and processed on the daemon side Excellent. The correct answer is to create a CSImportExtension. That extension point hands you the file you're indexing, side stepping the entire issue. Looking at the documentation for CSImportExtension it appears that this is for gathering & updating information about a file, not the items in the file. The extension only gets one CSSearchableItemAttributeSet that is for metadata about the file. An object that provides searchable attributes for file types that the app supports. Even if I wanted to misuse the API just to trigger a full reindex of the file contents, due to sandbox restrictions I don't think it would be possible to open an arbitrary file. The user would have to select the file in an Open dialog. My current solution is: When a document is opened start a Task that gathers all of the uniqueIdentifiers of the searchableItems for this file from the search index (using the contentURL to filter the results). Gather the mo
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’25
Reply to Complex Swift Data Relationships...
You haven't told us exactly what your issue is but something I spotted with your design that I don't think is correct is the relationship between Teacher and Student. As I see it your design will be simpler and more correct if you complete remove that relationship. A teacher holds (has) one or more classes A student attends (has) one or more classes So indirectly you have the relationship between Teacher and Student via the SchoolClass model. A bit unrelated but I prefer to use the @Relationship macro with the inverted argument for one of the relationship properties since it makes the code clearer for me (and it is also helpful for SwiftData)
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’25
Type ReferenceWritableKeyPath does not conform to the 'Sendable' protocol
This is not a question but more of a hint where I was having trouble with. In my SwiftData App I wanted to move from Swift 5 to Swift 6, for that, as recommended, I stayed in Swift 5 language mode and set 'Strict Concurrency Checking' to 'Complete' within my build settings. It marked all the places where I was using predicates with the following warning: Type '' does not conform to the 'Sendable' protocol; this is an error in the Swift 6 language mode I had the same warnings for SortDescriptors. I spend quite some time searching the web and wrapping my head around how to solve that issue to be able to move to Swift 6. In the end I found this existing issue in the repository of the Swift Language https://github.com/swiftlang/swift/issues/68943. It says that this is not a warning that should be seen by the developer and in fact when turning Swift 6 language mode on those issues are not marked as errors. So if anyone is encountering this when trying to fix all issues while staying in Swift 5 language mo
Replies
3
Boosts
0
Views
1.1k
Activity
Jun ’25
Reply to Type ReferenceWritableKeyPath does not conform to the 'Sendable' protocol
I ran into the same error message when using #Predicate in SwiftData @Query with Xcode 26.0 beta 2, Swift Language Version Swift 6, and Setting Default Actor Isolation on MainActore (section Swift Compiler - Concurrency). Setting the Default Actor Isolation to nonisolated and inserting @MainActor above @Observable inside the code resolved the problem.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’25