Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

Reply to Multiple Executables in a Single Bundle Fails to Launch Others After Codesign
Quinn! Thank you for your efforts and details. Your posts on this forum have been a lifesaver for those of us new to the world of Apple development/deployment. Current Entitlements Each of our executables require the same entitlements: com.apple.security.app-sandbox com.apple.security.cs.disable-library-validation com.apple.security.files.user-selected.read-write com.apple.security.network.client com.apple.security.network.server From the research into the articles you posted, it seems like these are all safe to inherit but I could be wrong about that! And if it's all going to TestFlight then I suppose it's restricted? The lib validation is disabled because we include a plugin ecosystem through Qt. I've tried adding the com.apple.security.inherit in our entitlements but am still seeing the same issue. Here's the entitlements for the exec_b (and exec_a) > codesign -d --entitlements - exec_b Executable=/Users/foo/src/SomeApp.app/Contents/MacOS/exec_b [Dict] [Key] com.apple.security.app-sandbox [Valu
Topic: Code Signing SubTopic: General Tags:
Mar ’25
Does @Relationship(inverse:) create a memory leak?
Hi, I am creating (or trying to) my first app using SwiftData - and I have questions :-) The main question I can't get my head wrapped around is the following: Let's say I have the sample below... @Model class Person { @Relationship(inverse:Hat.owner) var hat:Hat } @Model class Hat { var owner:Person? } It looks like I am creating a strong reference cycle between the person and the hat objects? And in fact I am seeing these kinds of reference cycles when I look at the memory debugger. Many code samples I have seen so far use this type of relationship declaration... And I am wondering: Am I missing something? Admittedly I don't find many discussions about memory leaks caused by SwiftData despite the syntax being used in many examples? So what is the situation? Did Apple just miss to explain that the inverse: declaration causes memory leaks or is there some kind of magic that I should understand?
2
0
164
Mar ’25
Reply to Multiple Executables in a Single Bundle Fails to Launch Others After Codesign
It should be possible to get this setup working. You mentioned TestFlight, which suggests you’re targeting the Mac App Store. If so, all your executables must be sandboxed. If you plan to spawn exec_a as a child process of exec_b then exec_b has to use sandbox inheritance. See Resolving App Sandbox Inheritance Problems. The other potential gotcha is entitlements. If exec_a uses restricted entitlements [1] then those entitlements get authorised by the provisioning profile embedded in the app bundle. If exec_b also needs restricted entitlements then things get trickier. So, does exec_b need any restricted entitlements? A restricted entitlement is one that must be authorised by a profile, as explained in TN3125 Inside Code Signing: Provisioning Profiles. Finally, I have a bunch of hints and tips on this topic in Resolving Trusted Execution Problems. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = eskimo + 1 + @ + apple.com [1] Which it’ll need for a Tes
Topic: Code Signing SubTopic: General Tags:
Mar ’25
Reply to SwiftData migration error: NSCloudKitMirroringDelegate are not reusable
Same error, i don't even have a migration, and all of sudden my project stopped working and the app launches and is stuck on first screen. If I disable by doing .cloudKitDatabase: .none. It will be able to run again. The issue is, I didn't even modify my SwiftData models between my last good build from 6 hours ago to this current build. I can still install the last good build from TestFlight and regain my cloudkit features, but i'm currently stuck with my development because of this issue.
Mar ’25
Reply to SwiftData migration error: NSCloudKitMirroringDelegate are not reusable
@DTS Engineer I'm experiencing the exact same errors when attempting to perform a SwiftData custom migration with relatively simple models. Are there any updates you could share with us? Right now it seems like SwiftData isn't usable since this error is unavoidable when syncing to CloudKit, unless of course you never need to migrate, which unfortunately isn't realistic. Thanks!
Mar ’25
Proposal for a Privacy-Focused, iOS-Exclusive Dating App
Hello Apple Developers, I’m reaching out to the community with a concept that I truly believe could be a natural fit for the Apple ecosystem: A privacy-focused, iOS-exclusive dating app designed to enhance connections between Apple users while staying true to Apple’s commitment to security and user privacy. The idea is to create an iOS-only dating platform that fosters relationships between users who are part of the Apple ecosystem. The app would integrate seamlessly with Apple’s services (iMessage, FaceTime, Siri, etc.) and provide a premium user experience, where privacy is a priority. Apple users already prefer to communicate using Apple services (iMessage, FaceTime). A dating app designed specifically for iOS users would deepen this ecosystem lock-in, making it easier for Apple customers to connect within a trusted space. Apple is already known for its privacy focus, and an iOS-exclusive dating app would build upon that reputation. It would ensure secure, private interactions, minimizing the risk
1
0
538
Mar ’25
Reply to SortDescriptor from a generic method crashes Xcode Previews but not Simulator.
Thank you for your time replying. Yeah I had many problems a year or two ago in getting the container right. But I think it ok at the moment especially as it works fine creating a SortDescriptor one way, but creating it the other way (without changing anything else) causes the crash. I copied only the necessary code to a basic app today so the whole thing fits in here. There are actually 2 files with previews and they add the model container in different ways: .modelContainer(PreviewDataController.previewContainer) .modelContainer(for: Item.self, inMemory: true) So the problem is probably else where. import SwiftData @main struct MyAppApp: App { var sharedModelContainer: ModelContainer = { let schema = Schema([ Item.self, ]) let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) do { return try ModelContainer(for: schema, configurations: [modelConfiguration]) } catch { fatalError(Could not create ModelContainer: (error)) } }() var body: some Scene { WindowGroup { Con
Mar ’25
Reply to SwiftData relationshipKeyPathsForPrefetching not working
It looks like I can work around part of the problem by executing the fetch for the related models directly. SwiftData will then properly use them as a cache. // Fetch accounts var fd = FetchDescriptor() let accounts = modelContext.fetch(fd) // CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZACCOUNTID FROM ZACCOUNT t0 // CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZORDERID, t0.ZTIMESTAMP, t0.ZACCOUNT, t0.ZORDERITEMS FROM ZORDER t0 WHERE t0.ZACCOUNT IN (SELECT * FROM _Z_intarray0) ORDER BY t0.ZACCOUNT // Fetch related orders for accounts let accArray = accounts.map { $0.persistentModelID } var fd2 = FetchDescriptor() fd2.predicate = #Predicate { if let account = $0.account { accArray.contains(account.persistentModelID) } else { false } } let orders = try? modelContext.fetch(fd2) // CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZORDERID, t0.ZTIMESTAMP, t0.ZACCOUNT, t0.ZORDERITEMS FROM ZORDER t0 WHERE (CASE ((CASE ( t0.ZACCOUNT IS NOT NULL) when 1 then ((CASE ( t0.ZACCOUNT IN (SELECT * FROM _Z_intarr
Mar ’25
Reply to Using any SwiftData Query causes app to hang
The way you create a dynamic Query, as shown in your code snippet, doesn't have anything wrong. The SwiftData version of the Adopting SwiftData for a Core Data app sample does the same thing (in TripListView.swift). To figure out why your app becomes unresponsive, your might consider profiling your app using Instruments. I'm guessing that the real issue may be that the init is called many times, followed by the view body getter that accesses the query result being triggered many times. You can quickly check if that is the case by adding logs in the following way: var body: some View { print((#function)) let _ = Self._printChanges() ... } Best, —— Ziqiao Chen  Worldwide Developer Relations.
Mar ’25
@Query with Set
How do I filter data using @Query with a Set of DateComponents? I successfully saved multiple dates using a MultiDatePicker in AddView.swift. In ListView.swift, I want to retrieve all records for the current or today’s date. There are hundreds of examples using @Query with strings and dates, but I haven’t found an example of @Query using a Set of DateComponents Nothing will compile and after hundreds and hundreds of attempts, my hair is turning gray. Please, please, please help me. For example, if the current date is Tuesday, March 4 205, then I want to retrieve both records. Since both records contain Tuesday, March 4, then retrieve both records. Sorting works fine because the order by clause uses period which is a Double. Unfortunately, my syntax is incorrect and I don’t know the correct predicate syntax for @Query and a Set of DateComponents. Class Planner.swift file import SwiftUI import SwiftData 
 @Model class Planner { //var id: UUID = UUID() var grade: Double = 4.0 var kumi: Double = 4.0 var
1
0
127
Mar ’25
Reply to "BAD_REQUEST" in iCloudKit Telemetry
BAD_REQUEST typically means that the CloudKit server receives an invalid request. That can happen when, for example, your request has a CloudKit record or field that doesn't exist in the CloudKit schema. You mentioned your development scheme had been fully deployed to production, but that doesn't completely rule out the possibility of having invalid requests. For example, if you are using Core Data / SwiftData + CloudKit (NSPersistentCloudKitContainer), and the Core Data / SwiftData model in your app isn't completely mapped to the CloudKit schema, a bad request may happen. What CloudKit API are you using? For Core Data / SwiftData + CloudKit and the CloudKit framework, you might consider capturing and analyzing a sysdiagnose to hopefully find detailed messages that indicate the concrete reason of a bad request. If you are only using NSUbiquitousKeyValueStore, or using file system APIs to access iCloud Drive, you don't directly get involved to CloudKit requests, and so I’d suggest th
Mar ’25
Critical: Cannot Deploy CloudKit Schema to Production Environment - Internal Error
Hi Developer Community, I'm experiencing a critical issue with CloudKit schema deployment that's blocking my app release. I've been trying to resolve this for several days and would appreciate any assistance from the community or Apple engineers. Issue Description I'm unable to deploy my CloudKit schema from development to production environment. When attempting to deploy through the CloudKit Dashboard, I either get an Internal Error message or the deployment button is disabled. Environment Details App: Reef Trak (Reef aquarium tracking app) CloudKit Container: ************ Development Environment: Schema fully defined and working correctly Production Environment: No schema deployed (confirmed in dashboard) What I've Tried Using the Deploy Schema to Production button in CloudKit Dashboard (results in Internal Error) Exporting schema from development and importing to production (fails) Using CloudKit CLI tools with API token (results in invalid-scope errors) Waiting 24-48 hours between attempts in case of prop
3
0
242
Mar ’25
Reply to Debugging/Fixing deleted relationship objects with SwiftData
Thanks. That worked in this simple project, but not in my full project. I'm not yet sure what the difference is, but it throws the instance was invalidated error when setting object.relationship = nil I've resorted to using sqlite directly (with the SQLite.swift package) and then setting to nil with a separate query: class IntegrityCheck { var model: String var relationship: String var relationshipType: String var count: Int64 = 0 var checked: Bool = false var orphanedObjectPKs: [Int64] = [] init(model: String, relationship: String, relationshipType: String) { self.model = model self.relationship = relationship self.relationshipType = relationshipType } init(model: String, relationship: String) { self.model = model self.relationship = relationship self.relationshipType = relationship } func run(modelContext: ModelContext) { guard let db = modelContext.sqliteDatabase else { print(could not get sqlite database) return } do { let query = try db.prepare(sql) c
Mar ’25
Reply to SwiftData migration error: NSCloudKitMirroringDelegate are not reusable
@sroy I just faced exactly same error this morning, with a trivial migration like yours. I just needed to add a new field with default value to a model, actually it can be migrated automatically but I needed to do some additional work so I created a migration plan. And now it turned out there is a system bug with CloudKit that was supposed to be fixed! I wonder so no one can do SwiftData migration now? let assume most people use iCloud sync.
Mar ’25
Reply to Multiple Executables in a Single Bundle Fails to Launch Others After Codesign
Quinn! Thank you for your efforts and details. Your posts on this forum have been a lifesaver for those of us new to the world of Apple development/deployment. Current Entitlements Each of our executables require the same entitlements: com.apple.security.app-sandbox com.apple.security.cs.disable-library-validation com.apple.security.files.user-selected.read-write com.apple.security.network.client com.apple.security.network.server From the research into the articles you posted, it seems like these are all safe to inherit but I could be wrong about that! And if it's all going to TestFlight then I suppose it's restricted? The lib validation is disabled because we include a plugin ecosystem through Qt. I've tried adding the com.apple.security.inherit in our entitlements but am still seeing the same issue. Here's the entitlements for the exec_b (and exec_a) > codesign -d --entitlements - exec_b Executable=/Users/foo/src/SomeApp.app/Contents/MacOS/exec_b [Dict] [Key] com.apple.security.app-sandbox [Valu
Topic: Code Signing SubTopic: General Tags:
Replies
Boosts
Views
Activity
Mar ’25
Does @Relationship(inverse:) create a memory leak?
Hi, I am creating (or trying to) my first app using SwiftData - and I have questions :-) The main question I can't get my head wrapped around is the following: Let's say I have the sample below... @Model class Person { @Relationship(inverse:Hat.owner) var hat:Hat } @Model class Hat { var owner:Person? } It looks like I am creating a strong reference cycle between the person and the hat objects? And in fact I am seeing these kinds of reference cycles when I look at the memory debugger. Many code samples I have seen so far use this type of relationship declaration... And I am wondering: Am I missing something? Admittedly I don't find many discussions about memory leaks caused by SwiftData despite the syntax being used in many examples? So what is the situation? Did Apple just miss to explain that the inverse: declaration causes memory leaks or is there some kind of magic that I should understand?
Replies
2
Boosts
0
Views
164
Activity
Mar ’25
Reply to Multiple Executables in a Single Bundle Fails to Launch Others After Codesign
It should be possible to get this setup working. You mentioned TestFlight, which suggests you’re targeting the Mac App Store. If so, all your executables must be sandboxed. If you plan to spawn exec_a as a child process of exec_b then exec_b has to use sandbox inheritance. See Resolving App Sandbox Inheritance Problems. The other potential gotcha is entitlements. If exec_a uses restricted entitlements [1] then those entitlements get authorised by the provisioning profile embedded in the app bundle. If exec_b also needs restricted entitlements then things get trickier. So, does exec_b need any restricted entitlements? A restricted entitlement is one that must be authorised by a profile, as explained in TN3125 Inside Code Signing: Provisioning Profiles. Finally, I have a bunch of hints and tips on this topic in Resolving Trusted Execution Problems. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = eskimo + 1 + @ + apple.com [1] Which it’ll need for a Tes
Topic: Code Signing SubTopic: General Tags:
Replies
Boosts
Views
Activity
Mar ’25
Reply to SwiftData migration error: NSCloudKitMirroringDelegate are not reusable
Same error, i don't even have a migration, and all of sudden my project stopped working and the app launches and is stuck on first screen. If I disable by doing .cloudKitDatabase: .none. It will be able to run again. The issue is, I didn't even modify my SwiftData models between my last good build from 6 hours ago to this current build. I can still install the last good build from TestFlight and regain my cloudkit features, but i'm currently stuck with my development because of this issue.
Replies
Boosts
Views
Activity
Mar ’25
Reply to SwiftData migration error: NSCloudKitMirroringDelegate are not reusable
@DTS Engineer I'm experiencing the exact same errors when attempting to perform a SwiftData custom migration with relatively simple models. Are there any updates you could share with us? Right now it seems like SwiftData isn't usable since this error is unavoidable when syncing to CloudKit, unless of course you never need to migrate, which unfortunately isn't realistic. Thanks!
Replies
Boosts
Views
Activity
Mar ’25
Proposal for a Privacy-Focused, iOS-Exclusive Dating App
Hello Apple Developers, I’m reaching out to the community with a concept that I truly believe could be a natural fit for the Apple ecosystem: A privacy-focused, iOS-exclusive dating app designed to enhance connections between Apple users while staying true to Apple’s commitment to security and user privacy. The idea is to create an iOS-only dating platform that fosters relationships between users who are part of the Apple ecosystem. The app would integrate seamlessly with Apple’s services (iMessage, FaceTime, Siri, etc.) and provide a premium user experience, where privacy is a priority. Apple users already prefer to communicate using Apple services (iMessage, FaceTime). A dating app designed specifically for iOS users would deepen this ecosystem lock-in, making it easier for Apple customers to connect within a trusted space. Apple is already known for its privacy focus, and an iOS-exclusive dating app would build upon that reputation. It would ensure secure, private interactions, minimizing the risk
Replies
1
Boosts
0
Views
538
Activity
Mar ’25
Reply to SortDescriptor from a generic method crashes Xcode Previews but not Simulator.
Thank you for your time replying. Yeah I had many problems a year or two ago in getting the container right. But I think it ok at the moment especially as it works fine creating a SortDescriptor one way, but creating it the other way (without changing anything else) causes the crash. I copied only the necessary code to a basic app today so the whole thing fits in here. There are actually 2 files with previews and they add the model container in different ways: .modelContainer(PreviewDataController.previewContainer) .modelContainer(for: Item.self, inMemory: true) So the problem is probably else where. import SwiftData @main struct MyAppApp: App { var sharedModelContainer: ModelContainer = { let schema = Schema([ Item.self, ]) let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) do { return try ModelContainer(for: schema, configurations: [modelConfiguration]) } catch { fatalError(Could not create ModelContainer: (error)) } }() var body: some Scene { WindowGroup { Con
Replies
Boosts
Views
Activity
Mar ’25
Reply to SwiftData relationshipKeyPathsForPrefetching not working
It looks like I can work around part of the problem by executing the fetch for the related models directly. SwiftData will then properly use them as a cache. // Fetch accounts var fd = FetchDescriptor() let accounts = modelContext.fetch(fd) // CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZACCOUNTID FROM ZACCOUNT t0 // CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZORDERID, t0.ZTIMESTAMP, t0.ZACCOUNT, t0.ZORDERITEMS FROM ZORDER t0 WHERE t0.ZACCOUNT IN (SELECT * FROM _Z_intarray0) ORDER BY t0.ZACCOUNT // Fetch related orders for accounts let accArray = accounts.map { $0.persistentModelID } var fd2 = FetchDescriptor() fd2.predicate = #Predicate { if let account = $0.account { accArray.contains(account.persistentModelID) } else { false } } let orders = try? modelContext.fetch(fd2) // CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZORDERID, t0.ZTIMESTAMP, t0.ZACCOUNT, t0.ZORDERITEMS FROM ZORDER t0 WHERE (CASE ((CASE ( t0.ZACCOUNT IS NOT NULL) when 1 then ((CASE ( t0.ZACCOUNT IN (SELECT * FROM _Z_intarr
Replies
Boosts
Views
Activity
Mar ’25
Reply to Using any SwiftData Query causes app to hang
The way you create a dynamic Query, as shown in your code snippet, doesn't have anything wrong. The SwiftData version of the Adopting SwiftData for a Core Data app sample does the same thing (in TripListView.swift). To figure out why your app becomes unresponsive, your might consider profiling your app using Instruments. I'm guessing that the real issue may be that the init is called many times, followed by the view body getter that accesses the query result being triggered many times. You can quickly check if that is the case by adding logs in the following way: var body: some View { print((#function)) let _ = Self._printChanges() ... } Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Mar ’25
Reply to SortDescriptor from a generic method crashes Xcode Previews but not Simulator.
Hi, Sorry to hear you are having problems getting previews working. This most commonly is seen when previews don't have a SwiftData model container configured correctly. Could you show how you are setting up your preview? I am looking for your #Preview definition + any custom PreviewModifier s you are using.
Replies
Boosts
Views
Activity
Mar ’25
@Query with Set
How do I filter data using @Query with a Set of DateComponents? I successfully saved multiple dates using a MultiDatePicker in AddView.swift. In ListView.swift, I want to retrieve all records for the current or today’s date. There are hundreds of examples using @Query with strings and dates, but I haven’t found an example of @Query using a Set of DateComponents Nothing will compile and after hundreds and hundreds of attempts, my hair is turning gray. Please, please, please help me. For example, if the current date is Tuesday, March 4 205, then I want to retrieve both records. Since both records contain Tuesday, March 4, then retrieve both records. Sorting works fine because the order by clause uses period which is a Double. Unfortunately, my syntax is incorrect and I don’t know the correct predicate syntax for @Query and a Set of DateComponents. Class Planner.swift file import SwiftUI import SwiftData 
 @Model class Planner { //var id: UUID = UUID() var grade: Double = 4.0 var kumi: Double = 4.0 var
Replies
1
Boosts
0
Views
127
Activity
Mar ’25
Reply to "BAD_REQUEST" in iCloudKit Telemetry
BAD_REQUEST typically means that the CloudKit server receives an invalid request. That can happen when, for example, your request has a CloudKit record or field that doesn't exist in the CloudKit schema. You mentioned your development scheme had been fully deployed to production, but that doesn't completely rule out the possibility of having invalid requests. For example, if you are using Core Data / SwiftData + CloudKit (NSPersistentCloudKitContainer), and the Core Data / SwiftData model in your app isn't completely mapped to the CloudKit schema, a bad request may happen. What CloudKit API are you using? For Core Data / SwiftData + CloudKit and the CloudKit framework, you might consider capturing and analyzing a sysdiagnose to hopefully find detailed messages that indicate the concrete reason of a bad request. If you are only using NSUbiquitousKeyValueStore, or using file system APIs to access iCloud Drive, you don't directly get involved to CloudKit requests, and so I’d suggest th
Replies
Boosts
Views
Activity
Mar ’25
Critical: Cannot Deploy CloudKit Schema to Production Environment - Internal Error
Hi Developer Community, I'm experiencing a critical issue with CloudKit schema deployment that's blocking my app release. I've been trying to resolve this for several days and would appreciate any assistance from the community or Apple engineers. Issue Description I'm unable to deploy my CloudKit schema from development to production environment. When attempting to deploy through the CloudKit Dashboard, I either get an Internal Error message or the deployment button is disabled. Environment Details App: Reef Trak (Reef aquarium tracking app) CloudKit Container: ************ Development Environment: Schema fully defined and working correctly Production Environment: No schema deployed (confirmed in dashboard) What I've Tried Using the Deploy Schema to Production button in CloudKit Dashboard (results in Internal Error) Exporting schema from development and importing to production (fails) Using CloudKit CLI tools with API token (results in invalid-scope errors) Waiting 24-48 hours between attempts in case of prop
Replies
3
Boosts
0
Views
242
Activity
Mar ’25
Reply to Debugging/Fixing deleted relationship objects with SwiftData
Thanks. That worked in this simple project, but not in my full project. I'm not yet sure what the difference is, but it throws the instance was invalidated error when setting object.relationship = nil I've resorted to using sqlite directly (with the SQLite.swift package) and then setting to nil with a separate query: class IntegrityCheck { var model: String var relationship: String var relationshipType: String var count: Int64 = 0 var checked: Bool = false var orphanedObjectPKs: [Int64] = [] init(model: String, relationship: String, relationshipType: String) { self.model = model self.relationship = relationship self.relationshipType = relationshipType } init(model: String, relationship: String) { self.model = model self.relationship = relationship self.relationshipType = relationship } func run(modelContext: ModelContext) { guard let db = modelContext.sqliteDatabase else { print(could not get sqlite database) return } do { let query = try db.prepare(sql) c
Replies
Boosts
Views
Activity
Mar ’25
Reply to SwiftData migration error: NSCloudKitMirroringDelegate are not reusable
@sroy I just faced exactly same error this morning, with a trivial migration like yours. I just needed to add a new field with default value to a model, actually it can be migrated automatically but I needed to do some additional work so I created a migration plan. And now it turned out there is a system bug with CloudKit that was supposed to be fixed! I wonder so no one can do SwiftData migration now? let assume most people use iCloud sync.
Replies
Boosts
Views
Activity
Mar ’25