Search results for

“SwiftData inheritance relationship”

4,981 results found

Post

Replies

Boosts

Views

Activity

Reply to How to handle required @relationship optionals in SwiftData CloudKit?
SwiftData + CloudKit uses NSPersistentCloudKitContainer under the hood, which requires all relationships must be optional. For more information, see Creating a Core Data Model for CloudKit. The requirement exists because of the latency of the synchronization: When you create an object graph in device A, which is being synchronized to device B, the system doesn't guarantee to synchronize the whole graph all at once. As a result, it's possible that an object is synchronized but its relationship is not. This situation is expressed as the relationship being nil. By checking if the relationship is nil, the app instance running on device B can consume the object appropriately. In your case, wrapping a relationship with a computed property to return an empty array if nil makes sense to me, if the other part of your app prefers to consume an empty array. It doesn't matter if the data is big or small. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Oct ’25
Reply to Privileged Helper is denied permission to open raw device
Passing along a few notes that may be helpful... First off, yes, this is the block that prevents normal access: At this point, the OS should trigger an interactive dialog, requesting scoped permissions to removable volumes. This works here: First, trigger the OS to intercept a C syscall on the main GUI process: ...because your secondary process is able to inherit its access from the GUI process. Related to this: Manual 'sudo ./helper' call succeeds, however. I suspect this worked because you'd previously granted Terminal.app FDA (Full Disk Access). Without that, you should have either triggered the same volume access dialog or failed (I'm not sure which would have happened). __ Kevin Elliott DTS Engineer, CoreOS/Hardware
Topic: App & System Services SubTopic: Core OS Tags:
Oct ’25
How to handle required @relationship optionals in SwiftData CloudKit?
Hi all, As you know, when using SwiftData Cloudkit, all relationships are required to be optional. In my app, which is a list app, I have a model class Project that contains an array of Subproject model objects. A Subproject also contains an array of another type of model class and this chain goes on and on. In this type of pattern, it becomes really taxxing to handle the optionals the correct way, i.e. unwrap them as late as possible and display an error to the user if unable to. It seems like most developers don't even bother, they just wrap the array in a computed property that returns an empty array if nil. I'm just wondering what is the recommended way by Apple to handle these optionals. I'm not really familiar with how the CloudKit backend works, but if you have a simple list app that only saves to the users private iCloud, can I just handwave the optionals like so many do? Is it only big data apps that need to worry? Or should we always strive to handle them the correct way? If that's
3
0
199
Oct ’25
Reply to Privileged Helper is denied permission to open raw device
I think I've finally and by accident achieved a solution. For those who come after... First, trigger the OS to intercept a C syscall on the main GUI process: const fd = c.open(/dev/disk4, c.O_RDWR, @as(c_uint, 0)); // this should return an access denied error, that's OK if (fd < 0) do_nothing() else _ = c.close(fd); At this point, the OS should trigger an interactive dialog, requesting scoped permissions to Removable Volumes. At this point, the Privileged Helper should inherit the permission from the main GUI process and be permitted to write to block device. Repeat C open() syscall procedure on the helper for good measure. Here, however, do not ignore Access Denied error.
Topic: App & System Services SubTopic: Core OS Tags:
Oct ’25
can't submit version with App Store Connect Api
I’m currently automating our iOS release pipeline with the App Store Connect API. TestFlight and App Store version creation are mostly working, but I’m stuck at the “submit for review” step. Below are the endpoint I’m calling, the payload, and the error I receive: > url: https://api.appstoreconnect.apple.com/v1/appStoreReviewSubmissions > method: POST > params: None > json: {'data': {'type': 'appStoreReviewSubmissions', 'relationships': {'appStoreVersion': {'data': {'type': 'appStoreVersions', 'id': '62db20b9-1bc6-4b1a-9b52-9834a807c377'}}}}} > response: > ASCAPIError(404): The specified resource does not exist: The path provided does not match a defined resource type. | errors=[{'id': '32d2c224-0f1c-4592-a02d-a4f87b13b6b7', 'status': '404', 'code': 'NOT_FOUND', 'title': 'The specified resource does not exist', 'detail': 'The path provided does not match a defined resource type.'}] The official documentation app-store-version-submissions doesn't mention the endpoint, and I could no
0
0
202
Sep ’25
Issue with SwiftData inheritance
Every time I insert a subclass (MYShapeLayer) into the model context, the app crashes with an error: DesignerPlayground crashed due to fatalError in BackingData.swift at line 908. Never access a full future backing data - PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(backing: SwiftData.PersistentIdentifier.PersistentIdentifierBacking.managedObjectID(0xb2dbc55f3f4c57f2 ))) with Optional(A6CA4F89-107F-4A66-BC49-DD7DAC689F77) struct ContentView: View { @Environment(.modelContext) private var modelContext @Query private var designs: [MYDesign] var layers: [MYLayer] { designs.first?.layers ?? [] } var body: some View { NavigationStack { List { ForEach(layers) { layer in Text(layer.description) } } .onAppear { let design = MYDesign(title: My Design) modelContext.insert(design) try? modelContext.save() } .toolbar { Menu(Add, systemImage: plus) { Button(action: addTextLayer) { Text(Add Text Layer) } Button(action: addShapeLayer) { Text(Add Shape Layer) } } } } } private func addTextLayer() { if let desig
1
0
163
Sep ’25
Reply to Background Assets file diff?
I performed the following code: let assetPackStatus = try await AssetPackManager. Shared. The status (ofAssetPackWithID: assetPackID) print(checkAssetPackStatus (assetPackStatus)). The content of the print assetPackStatus is:(BackgroundAssets. AssetPack. Status) assetPackStatus = (rawValue = 69). I couldn't find the explanation for this content in AssetPack.Status. Could you please tell me what it means. Thanks. AssetPack.Status is an option set, not an enumeration. One status value can include zero or more options. Its raw value is a mask on a bit field of the possible options. Each possible option is represented by a 1 bit at a particular location in the bit field—i.e., the binary representation of some power of 2. The bit mask selects some subset of those options. It’s just a sequence of bits, so it can be typed as an integer. In your case, the integer 69 in binary is 0b1000101. The three 1 bits, from right to left (least significant to most significant), correspond to 2⁰, 2², and 2⁶, respectively. Here’s
Sep ’25
SwiftData ModelActor causes 5-10 second UI freeze when opening sheet
I'm experiencing a significant UI freeze in my SwiftUI app that uses SwiftData with CloudKit sync. When users tap a button to present a sheet for the first time after app launch, the entire UI becomes unresponsive for 5-10 seconds. Subsequent sheet presentations work fine. App Architecture Service layer: An @Observable class marked with @MainActor that orchestrates operations Persistence layer: A @ModelActor class that handles SwiftData operations SwiftUI views: Using @Environment to access the service layer The structure looks like this: @Observable @MainActor final class MyServices { let persistence: DataPersistence init(modelContainer: ModelContainer) { self.persistence = DataPersistence(modelContainer: modelContainer) } func addItem(title: String) async { // Creates and saves an item through persistence layer } } @ModelActor actor DataPersistence { func saveItem(_ item: Item) async { // Save to SwiftData } } The app initializes the ModelContainer at the Scene level and passes it
2
0
149
Sep ’25
xcodebuild failing when package plugin is added to project
I have created a build tool plugin in one of my SPM packages, and am trying to get it working in my project. It works fine when I build from Xcode, or have at least built the project in Xcode once before with the plugin. But if I try to build the project using xcodebuild on a machine where I have never built the project before, it fails with this error: error: '2.3.0': Invalid manifest (compiled with: [/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc, -vfsoverlay, /var/folders/5_/q4yl04gs2kld1zztqxkqjdgh0000gq/T/TemporaryDirectory.BWwJWG/vfs.yaml, -L, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI, -lPackageDescription, -Xlinker, -rpath, -Xlinker, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI, -target, arm64-apple-macosx14.0, -sdk, /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk, -F, /Applicati
2
0
158
Sep ’25
Reply to @Attribute 'unique' and complex keys
This is a very nice addition to SwiftData, but there is still a problem (which I didn't mention in the original post). To the best of my knowledge, CloudKit still does not support (or enforce) unique properties. So, unless I'm missing something, this solution only works if you don't want take advantage of iCloud data synchronization services. Or am I missing something?
Sep ’25
swift
Hi, thank you for your reply. I have checked and confirmed that all AppleUser entity fields (id, name, email, password, createdAt) are optional, relationships (posts, comments) are optional, and I assign values when creating a new object, but Core Data still throws a nilError during registration; I have uploaded my project to GitHub for your reference here: https://github.com/Kawiichao/job. If reviewing it requires any payment, please let me know in advance. Thank you very much for your kind offer—I really appreciate it!
1
0
68
Sep ’25
Reply to iOS 26 SwiftData crash does not happen in iOS 16
The error message seems to indicate a type mis-match, likely the data in your JSON data being a number, while the corresponding SwiftData attribute being a string. That mismatch triggers an error when your app saves the SwiftData store. If you save your SwiftData store immediately after modelContext.insert(decodedResponse), as shown below, you will see the error: func getBestSellerLists() async { ... modelContext.insert(decodedResponse) // Add the following code to save the context and trigger the error. do { try modelContext.save() // This triggers the error. } catch { print(error) } ... } You can probably use the following flow to figure out which piece of data triggers the type mismatch: Add the code snippet above to your project so you can trigger the crash in a controlled way. Replace the JSON data from the remote server with a local JSON file so you can easily change data. Remove part of the data from the JSON file, change your SwiftData models to match the schema, an
Sep ’25
iOS 26 SwiftData crash does not happen in iOS 16
I have a simple app that makes an HTTPS call to gather some JSON which I then parse and add to my SwiftData database. The app then uses a simple @Query in a view to get the data into a list. on iOS 16 this works fine. No problems. But the same code on iOS 26 (targeting iOS 18.5) crashes after about 15 seconds of idle time after the list is populated. The error message is: Could not cast value of type '__NSCFNumber' (0x1f31ee568) to 'NSString' (0x1f31ec718). and occurs when trying to access ANY property of the list. I have a stripped down version of the app that shows the crash available. To replicate the issue: open the project in Xcode 26 target any iOS 26 device or simulator compile and run the project. after the list is displayed, wait about 15 seconds and the app crashes. It is also of note that if you try to run the app again, it will crash immediately, unless you delete the app from the device. Any help on this would be appreciated. Feedback number FB20295815 includes .zip file Below is the bas
4
0
261
Sep ’25
Reply to How to configure macOS app permission MANUALLY (not GUI)
The modeling tool is called MagicDraw, a UML modeling tool written in Java and originally created by a company No Magic, which was acquired by Dassault Systèmes. I have a long relationship with this company, so I have some insight into the tool, and some source code to support my customization work for special modeling strategies, however I have not enough sources to rebuild the tool on my own. The reason for the many copies is to keep one clean copy and then some copy s in various states of customization. After upgrading to Sequoia from Mojave, I started the clean copy of MagicDraw first, in the hope it would attach all security attributes to it. But unfortunately Sequoia picked one of the customized copies as the one and only entry in Privacy & Security -> Local Network. Since there is no GUI provision in Local Networks to add or remove applications, it requires some hacking (starting and killing of the app, combined with enabling and removing in Local Network) to provide the clean MagicDraw
Sep ’25
Reply to How to handle required @relationship optionals in SwiftData CloudKit?
SwiftData + CloudKit uses NSPersistentCloudKitContainer under the hood, which requires all relationships must be optional. For more information, see Creating a Core Data Model for CloudKit. The requirement exists because of the latency of the synchronization: When you create an object graph in device A, which is being synchronized to device B, the system doesn't guarantee to synchronize the whole graph all at once. As a result, it's possible that an object is synchronized but its relationship is not. This situation is expressed as the relationship being nil. By checking if the relationship is nil, the app instance running on device B can consume the object appropriately. In your case, wrapping a relationship with a computed property to return an empty array if nil makes sense to me, if the other part of your app prefers to consume an empty array. It doesn't matter if the data is big or small. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Oct ’25
Reply to Privileged Helper is denied permission to open raw device
Passing along a few notes that may be helpful... First off, yes, this is the block that prevents normal access: At this point, the OS should trigger an interactive dialog, requesting scoped permissions to removable volumes. This works here: First, trigger the OS to intercept a C syscall on the main GUI process: ...because your secondary process is able to inherit its access from the GUI process. Related to this: Manual 'sudo ./helper' call succeeds, however. I suspect this worked because you'd previously granted Terminal.app FDA (Full Disk Access). Without that, you should have either triggered the same volume access dialog or failed (I'm not sure which would have happened). __ Kevin Elliott DTS Engineer, CoreOS/Hardware
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Oct ’25
How to handle required @relationship optionals in SwiftData CloudKit?
Hi all, As you know, when using SwiftData Cloudkit, all relationships are required to be optional. In my app, which is a list app, I have a model class Project that contains an array of Subproject model objects. A Subproject also contains an array of another type of model class and this chain goes on and on. In this type of pattern, it becomes really taxxing to handle the optionals the correct way, i.e. unwrap them as late as possible and display an error to the user if unable to. It seems like most developers don't even bother, they just wrap the array in a computed property that returns an empty array if nil. I'm just wondering what is the recommended way by Apple to handle these optionals. I'm not really familiar with how the CloudKit backend works, but if you have a simple list app that only saves to the users private iCloud, can I just handwave the optionals like so many do? Is it only big data apps that need to worry? Or should we always strive to handle them the correct way? If that's
Replies
3
Boosts
0
Views
199
Activity
Oct ’25
Reply to Privileged Helper is denied permission to open raw device
I think I've finally and by accident achieved a solution. For those who come after... First, trigger the OS to intercept a C syscall on the main GUI process: const fd = c.open(/dev/disk4, c.O_RDWR, @as(c_uint, 0)); // this should return an access denied error, that's OK if (fd < 0) do_nothing() else _ = c.close(fd); At this point, the OS should trigger an interactive dialog, requesting scoped permissions to Removable Volumes. At this point, the Privileged Helper should inherit the permission from the main GUI process and be permitted to write to block device. Repeat C open() syscall procedure on the helper for good measure. Here, however, do not ignore Access Denied error.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Oct ’25
can't submit version with App Store Connect Api
I’m currently automating our iOS release pipeline with the App Store Connect API. TestFlight and App Store version creation are mostly working, but I’m stuck at the “submit for review” step. Below are the endpoint I’m calling, the payload, and the error I receive: > url: https://api.appstoreconnect.apple.com/v1/appStoreReviewSubmissions > method: POST > params: None > json: {'data': {'type': 'appStoreReviewSubmissions', 'relationships': {'appStoreVersion': {'data': {'type': 'appStoreVersions', 'id': '62db20b9-1bc6-4b1a-9b52-9834a807c377'}}}}} > response: > ASCAPIError(404): The specified resource does not exist: The path provided does not match a defined resource type. | errors=[{'id': '32d2c224-0f1c-4592-a02d-a4f87b13b6b7', 'status': '404', 'code': 'NOT_FOUND', 'title': 'The specified resource does not exist', 'detail': 'The path provided does not match a defined resource type.'}] The official documentation app-store-version-submissions doesn't mention the endpoint, and I could no
Replies
0
Boosts
0
Views
202
Activity
Sep ’25
Issue with SwiftData inheritance
Every time I insert a subclass (MYShapeLayer) into the model context, the app crashes with an error: DesignerPlayground crashed due to fatalError in BackingData.swift at line 908. Never access a full future backing data - PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(backing: SwiftData.PersistentIdentifier.PersistentIdentifierBacking.managedObjectID(0xb2dbc55f3f4c57f2 ))) with Optional(A6CA4F89-107F-4A66-BC49-DD7DAC689F77) struct ContentView: View { @Environment(.modelContext) private var modelContext @Query private var designs: [MYDesign] var layers: [MYLayer] { designs.first?.layers ?? [] } var body: some View { NavigationStack { List { ForEach(layers) { layer in Text(layer.description) } } .onAppear { let design = MYDesign(title: My Design) modelContext.insert(design) try? modelContext.save() } .toolbar { Menu(Add, systemImage: plus) { Button(action: addTextLayer) { Text(Add Text Layer) } Button(action: addShapeLayer) { Text(Add Shape Layer) } } } } } private func addTextLayer() { if let desig
Replies
1
Boosts
0
Views
163
Activity
Sep ’25
Reply to Background Assets file diff?
I performed the following code: let assetPackStatus = try await AssetPackManager. Shared. The status (ofAssetPackWithID: assetPackID) print(checkAssetPackStatus (assetPackStatus)). The content of the print assetPackStatus is:(BackgroundAssets. AssetPack. Status) assetPackStatus = (rawValue = 69). I couldn't find the explanation for this content in AssetPack.Status. Could you please tell me what it means. Thanks. AssetPack.Status is an option set, not an enumeration. One status value can include zero or more options. Its raw value is a mask on a bit field of the possible options. Each possible option is represented by a 1 bit at a particular location in the bit field—i.e., the binary representation of some power of 2. The bit mask selects some subset of those options. It’s just a sequence of bits, so it can be typed as an integer. In your case, the integer 69 in binary is 0b1000101. The three 1 bits, from right to left (least significant to most significant), correspond to 2⁰, 2², and 2⁶, respectively. Here’s
Replies
Boosts
Views
Activity
Sep ’25
SwiftData ModelActor causes 5-10 second UI freeze when opening sheet
I'm experiencing a significant UI freeze in my SwiftUI app that uses SwiftData with CloudKit sync. When users tap a button to present a sheet for the first time after app launch, the entire UI becomes unresponsive for 5-10 seconds. Subsequent sheet presentations work fine. App Architecture Service layer: An @Observable class marked with @MainActor that orchestrates operations Persistence layer: A @ModelActor class that handles SwiftData operations SwiftUI views: Using @Environment to access the service layer The structure looks like this: @Observable @MainActor final class MyServices { let persistence: DataPersistence init(modelContainer: ModelContainer) { self.persistence = DataPersistence(modelContainer: modelContainer) } func addItem(title: String) async { // Creates and saves an item through persistence layer } } @ModelActor actor DataPersistence { func saveItem(_ item: Item) async { // Save to SwiftData } } The app initializes the ModelContainer at the Scene level and passes it
Replies
2
Boosts
0
Views
149
Activity
Sep ’25
xcodebuild failing when package plugin is added to project
I have created a build tool plugin in one of my SPM packages, and am trying to get it working in my project. It works fine when I build from Xcode, or have at least built the project in Xcode once before with the plugin. But if I try to build the project using xcodebuild on a machine where I have never built the project before, it fails with this error: error: '2.3.0': Invalid manifest (compiled with: [/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc, -vfsoverlay, /var/folders/5_/q4yl04gs2kld1zztqxkqjdgh0000gq/T/TemporaryDirectory.BWwJWG/vfs.yaml, -L, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI, -lPackageDescription, -Xlinker, -rpath, -Xlinker, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI, -target, arm64-apple-macosx14.0, -sdk, /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk, -F, /Applicati
Replies
2
Boosts
0
Views
158
Activity
Sep ’25
Reply to BottomBar .searchable + Tab with Nav
The developer tutorial exhibits this issue nicely: https://developer.apple.com/tutorials/develop-in-swift/work-with-relationships
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’25
Reply to @Attribute 'unique' and complex keys
This is a very nice addition to SwiftData, but there is still a problem (which I didn't mention in the original post). To the best of my knowledge, CloudKit still does not support (or enforce) unique properties. So, unless I'm missing something, this solution only works if you don't want take advantage of iCloud data synchronization services. Or am I missing something?
Replies
Boosts
Views
Activity
Sep ’25
swift
Hi, thank you for your reply. I have checked and confirmed that all AppleUser entity fields (id, name, email, password, createdAt) are optional, relationships (posts, comments) are optional, and I assign values when creating a new object, but Core Data still throws a nilError during registration; I have uploaded my project to GitHub for your reference here: https://github.com/Kawiichao/job. If reviewing it requires any payment, please let me know in advance. Thank you very much for your kind offer—I really appreciate it!
Replies
1
Boosts
0
Views
68
Activity
Sep ’25
Reply to iOS 26 SwiftData crash does not happen in iOS 16
The error message seems to indicate a type mis-match, likely the data in your JSON data being a number, while the corresponding SwiftData attribute being a string. That mismatch triggers an error when your app saves the SwiftData store. If you save your SwiftData store immediately after modelContext.insert(decodedResponse), as shown below, you will see the error: func getBestSellerLists() async { ... modelContext.insert(decodedResponse) // Add the following code to save the context and trigger the error. do { try modelContext.save() // This triggers the error. } catch { print(error) } ... } You can probably use the following flow to figure out which piece of data triggers the type mismatch: Add the code snippet above to your project so you can trigger the crash in a controlled way. Replace the JSON data from the remote server with a local JSON file so you can easily change data. Remove part of the data from the JSON file, change your SwiftData models to match the schema, an
Replies
Boosts
Views
Activity
Sep ’25
iOS 26 SwiftData crash does not happen in iOS 16
I have a simple app that makes an HTTPS call to gather some JSON which I then parse and add to my SwiftData database. The app then uses a simple @Query in a view to get the data into a list. on iOS 16 this works fine. No problems. But the same code on iOS 26 (targeting iOS 18.5) crashes after about 15 seconds of idle time after the list is populated. The error message is: Could not cast value of type '__NSCFNumber' (0x1f31ee568) to 'NSString' (0x1f31ec718). and occurs when trying to access ANY property of the list. I have a stripped down version of the app that shows the crash available. To replicate the issue: open the project in Xcode 26 target any iOS 26 device or simulator compile and run the project. after the list is displayed, wait about 15 seconds and the app crashes. It is also of note that if you try to run the app again, it will crash immediately, unless you delete the app from the device. Any help on this would be appreciated. Feedback number FB20295815 includes .zip file Below is the bas
Replies
4
Boosts
0
Views
261
Activity
Sep ’25
Reply to How to configure macOS app permission MANUALLY (not GUI)
The modeling tool is called MagicDraw, a UML modeling tool written in Java and originally created by a company No Magic, which was acquired by Dassault Systèmes. I have a long relationship with this company, so I have some insight into the tool, and some source code to support my customization work for special modeling strategies, however I have not enough sources to rebuild the tool on my own. The reason for the many copies is to keep one clean copy and then some copy s in various states of customization. After upgrading to Sequoia from Mojave, I started the clean copy of MagicDraw first, in the hope it would attach all security attributes to it. But unfortunately Sequoia picked one of the customized copies as the one and only entry in Privacy & Security -> Local Network. Since there is no GUI provision in Local Networks to add or remove applications, it requires some hacking (starting and killing of the app, combined with enabling and removing in Local Network) to provide the clean MagicDraw
Replies
Boosts
Views
Activity
Sep ’25