Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

Detecting When App Token Is Removed Due to Category Selection in FamilyActivityPicker
I'm working with the Screen Time API (FamilyActivityPicker) in SwiftUI and need help with a specific scenario. I'm using the FamilyActivityPicker to let users select apps and categories to block. I save the previous selection (both applicationTokens and categoryTokens) locally. When the user updates their selection, I compare the new selection with the saved one to determine which apps or categories were removed. However, I’m trying to handle a specific case: when an individual app token is removed from the selection because its entire category was selected instead. In this situation, even though the app is no longer in applicationTokens, it's still blocked due to its category being included in categoryTokens. Since I need to show users which apps were actually removed, I want to avoid listing apps that are still indirectly blocked via a selected category. I’ve created a mapping between ApplicationToken and FamilyActivityCategoryToken to check whether a removed app is still covered by a selected category befo
2
0
198
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
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
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
Apple Music API - relationships and views are broken
I am testing the Music API and I am hitting walls every single moment when I try to do something that is DOCUMENTED but doesn't work/exists. Documentation says, /v1/catalog/us/artists/{ID}/view/{view}/ NEVER returns 404, while I am getting 404 for even content I know it's available on Apple Music. e.g /v1/catalog/us/artists/1487603897/view/appears-on-albums/ results 404 while they are appearing on an album FRIGID TORTURE of Nosphere artist. So when I request for appears-on or featured albums it shoud appear as a result, but I get 404. It's here so it should appear: https://music.apple.com/us/album/frigid-silence/1791001624?i=1791001626 I found NO WAY to get that album for this artist using the API, which is very frustrating and annoying. Similarly if I try this: /v1/catalog/us/artists/{ID}?views=>appears-on-albums it will result an EMPTY array for the data property Also the documentation is unclear about the several limitation max values, many parameters (e.g. include parameters are unknown ) we can't tell
0
0
210
Jun ’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
Jun ’25
Failing to create leaderboard via the API
I'm getting the following error when attempting to create a leaderboard via the documented POST url. Here is the full error response: { errors : [ { id : xxxxxx, status : 400, code : ENTITY_INVALID, title : The request entity is not valid json, detail : The request entity data could not be processed. Please ensure you are sending valid json., meta : { position : { row : 1, column : 1 } } } ] } Except what I'm sending IS valid JSON, emitted directly from JsonUtility and verified via JSONLint: {data:{type:gameCenterLeaderboards,attributes:{defaultFormatter:INTEGER,referenceName:TEST_AUTO,vendorIdentifier:TEST_AUTO,submissionType:MOST_RECENT_SCORE,sortScoreType:DESC,scoreRangeStart:0,scoreRangeEnd:20000,recurrenceStartDate:2025-06-25T13:00:00Z,recurrenceDuration:PT30M,recurrenceRule:FREQ=HOURLY;INTERVAL=1},relationships:{gameCenterDetail:{data:{type:gameCenterDetails,id:xxxxxx}}}}} This follows EXACTLY the pattern in the App Store Connect documentation. I've even tried sending the example JSON they give
0
0
84
Jun ’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
Detecting When App Token Is Removed Due to Category Selection in FamilyActivityPicker
I'm working with the Screen Time API (FamilyActivityPicker) in SwiftUI and need help with a specific scenario. I'm using the FamilyActivityPicker to let users select apps and categories to block. I save the previous selection (both applicationTokens and categoryTokens) locally. When the user updates their selection, I compare the new selection with the saved one to determine which apps or categories were removed. However, I’m trying to handle a specific case: when an individual app token is removed from the selection because its entire category was selected instead. In this situation, even though the app is no longer in applicationTokens, it's still blocked due to its category being included in categoryTokens. Since I need to show users which apps were actually removed, I want to avoid listing apps that are still indirectly blocked via a selected category. I’ve created a mapping between ApplicationToken and FamilyActivityCategoryToken to check whether a removed app is still covered by a selected category befo
Replies
2
Boosts
0
Views
198
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
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 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
Apple Music API - relationships and views are broken
I am testing the Music API and I am hitting walls every single moment when I try to do something that is DOCUMENTED but doesn't work/exists. Documentation says, /v1/catalog/us/artists/{ID}/view/{view}/ NEVER returns 404, while I am getting 404 for even content I know it's available on Apple Music. e.g /v1/catalog/us/artists/1487603897/view/appears-on-albums/ results 404 while they are appearing on an album FRIGID TORTURE of Nosphere artist. So when I request for appears-on or featured albums it shoud appear as a result, but I get 404. It's here so it should appear: https://music.apple.com/us/album/frigid-silence/1791001624?i=1791001626 I found NO WAY to get that album for this artist using the API, which is very frustrating and annoying. Similarly if I try this: /v1/catalog/us/artists/{ID}?views=>appears-on-albums it will result an EMPTY array for the data property Also the documentation is unclear about the several limitation max values, many parameters (e.g. include parameters are unknown ) we can't tell
Replies
0
Boosts
0
Views
210
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
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
Jun ’25
Reply to SwiftData public sharing
Same issue for me. A bran new app coded with SwiftData and now I want to share models... And nothing really new regarding SwiftData at WWDV 25. upvote.
Replies
Boosts
Views
Activity
Jun ’25
Failing to create leaderboard via the API
I'm getting the following error when attempting to create a leaderboard via the documented POST url. Here is the full error response: { errors : [ { id : xxxxxx, status : 400, code : ENTITY_INVALID, title : The request entity is not valid json, detail : The request entity data could not be processed. Please ensure you are sending valid json., meta : { position : { row : 1, column : 1 } } } ] } Except what I'm sending IS valid JSON, emitted directly from JsonUtility and verified via JSONLint: {data:{type:gameCenterLeaderboards,attributes:{defaultFormatter:INTEGER,referenceName:TEST_AUTO,vendorIdentifier:TEST_AUTO,submissionType:MOST_RECENT_SCORE,sortScoreType:DESC,scoreRangeStart:0,scoreRangeEnd:20000,recurrenceStartDate:2025-06-25T13:00:00Z,recurrenceDuration:PT30M,recurrenceRule:FREQ=HOURLY;INTERVAL=1},relationships:{gameCenterDetail:{data:{type:gameCenterDetails,id:xxxxxx}}}}} This follows EXACTLY the pattern in the App Store Connect documentation. I've even tried sending the example JSON they give
Replies
0
Boosts
0
Views
84
Activity
Jun ’25