Search results for

“SwiftData inheritance relationship”

4,981 results found

Post

Replies

Boosts

Views

Activity

Reply to Is realtime multidevice persistence possible using SwiftData?
Even though this doesn’t provide a direct solution for cross-device real-time database persistence, it may simulate the behavior you’re looking for. If both devices are on the same network, you can leverage the MultipeerConnectivity framework to send data to other devices immediately and then persist it locally. This way you can achieve a “live update” experience within the Apple ecosystem, while still using SwiftData for storage.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’25
Is realtime multidevice persistence possible using SwiftData?
I really enjoyed using SwiftData for persistence until I found out that the CloudKit integration ensures changes are only eventually consistent, and that changes can propagate to other devices after as long as minutes, making it useless for any feature that involves handoff between devices. Devastating news but I guess it’s on me for nrtfm. I may try my hand at a custom model context DataStore integrating Powersync, but that’s a whole trip and before I embark on it I was wondering if anyone had suggestions for resolving this problem in a simple and elegant manager that allows me to keep as much of the machinery within Apple’s ecosystem as possible, while ensure reliable “live” updates to SwiftData stores on all eligible devices.
2
0
230
Aug ’25
SwiftData and CloudKit
Recently I've been working on a demo project called iLibrary. The main goal was to learn more about CloudKit and SwiftData. After a while I noticed that there were some hangs/freezes when running the app in debug mode. I first tried this with Xcode 15.4 and iOS 17.5. Here the hang only appears at the beginning, but only for a few seconds. But when I exit debug mode, there are no more hangs. With Xcode 16 beta 4 and iOS 18 it looks completely different. In this case, the hangs and freezes are always present, whether in debug mode or not. And it's not just at the beginning, it's throughout the app. I'm aware that this is still a beta, but I still find this weird. And when I profile this I see that the main thread gets quite overloaded. Interestingly, my app doesn't have that many operations going on. So I guess something with the sync of SwiftData or my CloudKitManger where I fetch some records from the public database is not running fine. Lastly, I wanted to delete the iCloud app data. So I w
9
0
1.8k
Aug ’25
Reply to SwiftData and CloudKit
The original post had been a year ago, and had run out of my radar since then, until this new post brought this back, thanks to @jenyalebid. If simply creating a SwiftData model container with CloudKit integration, which kicks off the initialization of NSPersistentCloudKitContainer under the hood, causes the hang, I'd suggest that you start with filing an actionable feedback report, because the initialization is not supposed to be a long task. SwiftData + CloudKit integration is based on NSPersistentCloudKitContainer, and so folks can follow the tips described in the following technote to analyze if there is anything goes wrong in the initialization phase: TN3163: Understanding the synchronization of NSPersistentCloudKitContainer If somebody can share a minimal project, with detailed steps, that reproduces the issue, I'd be able to take a look as well. The orignal post does contain a link, but it has been a year, and I am not sure if the issue is the same. Best, —— Ziqiao Chen  Worldwide De
Aug ’25
Reply to Is realtime multidevice persistence possible using SwiftData?
I don't have a lot to say about implementing a real-time data persistence system cross devices, but just to confirm that CloudKit isn't a real-time system, and so SwiftData / Core Data + CloudKit integration is not real time either, as you have found out. To optimize the overall experience, CloudKit even implemented a mechanism to throttle requests, if the rate is too high, as discussed in TN3162: Understanding CloudKit throttles. And yes, a custom data store will be the way to go, if you would use SwiftData. You need to take care the real-time synchronization part when going along this path. There is no system-provided framework specifically for that purpose. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’25
Reply to SwiftData and CloudKit
Could anyone from Apple weigh in on this? this is a real and easily reproducible issue. on active scenePhase, if CloudKit, specially SwiftData, is enabled… there is a noticeable hang first few seconds. I am assuming it has to do with the @Query sync with remote.
Aug ’25
Reply to How do I use IOUserSCSIPeripheralDeviceType00?
So, the first thing to understand here is that the IOKitPersonalities is called that because it IS in fact a fully valid IOKitPersonalities dictionary. That is, what the system actually uses that dictionary for is: Perform a standard IOKit match and load cycle in the kernel. The final driver in the kernel then uses the DEXT-specific data to launch and run your DEXT process outside the kernel. So, working through the critical keys in that dictionary: IOProviderClass-> This is the in-kernel class that your driver loads on top of. In your case, that would be IOSCSIPeripheralDeviceNub or one of its variants. IOClass-> This is the in-kernel class that your driver loads on top of. This is where things can become a bit confused, as some families work by: Routing all activity through the provider reference so that the DEXT-specific class does not matter (PCIDriverKit). Having the DEXT subclass a specific subclass which corresponds to a specific kernel driver (SCSIPeripheralsDriverKit). This distinction is descr
Aug ’25
Reply to SwiftData Inheritance Query Specialized Model
Nice to know that the original issue goes away in the latest Beta. Regarding the crash triggered by the access to Item.children, if you can provide a runnable code snippet to demo the issue, I'll take another look. You have mentioned a few classes with inheritance, and so I think it is probably worth mentioning that over-using inheritance may impact your app's performance negatively. Concretely, with today's default store (DefaultStore), all the types in an inheritance hierarchy are persisted with one single table in SQLite. If your inheritance hierarchy has many classes, the table (columns and data) can be quite big, which can slow down the performance of fetching and inserting data. That being said, when adopting SwiftData inheritance, you might examine if that is a right use case. This WWDC25 session(starting from around 4:25) covers this topic a bit. You can take a look, if haven't yet. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Aug ’25
Equatable with default actor isolation of MainActor
I filed the following issue on swiftlang/swift on GitHub (Aug 8th), and a followup the swift.org forums, but not getting any replies. As we near the release of Swift 6.2, I want to know if what I'm seeing below is expected, or if it's another case where the compiler needs a fix. protocol P1: Equatable { } struct S1: P1 { } // Error: Conformance of 'S1' to protocol 'P1' crosses into main actor-isolated code an can cause data races struct S1Workaround: @MainActor P1 { } // OK // Another potential workaround if `Equatable` conformance can be moved to the conforming type. protocol P2 { } struct S2: Equatable, P2 { } // OK There was a prior compiler bug fix which addressed inhereted protocols regarding @MainActor. For Equatable, one still has to use @MainActoreven when the default actor isolation is MainActor. Also affects Hashable and any other protocol inheriting from Equatable.
3
0
1.2k
Aug ’25
Reply to SwiftData Inheritance Query Specialized Model
Hi Ziqiao, I've tried with iOS 26 Beta 7 and since Beta 8 (landed tonight) on device (because my Xcode is stuck on iOS Beta 6, don't know why) and the problem is solved. I can now query CollectionItem with predicate that contains inherited properties. Now I have only got problems with accesses to the children property in List. When i got the following hierarchy and the SwiftUI view List access to the Item.children property I got another kind of crash. Category: Work (parent: none) Category: Tech (parent: Work) Thread 1: Fatal error: Never access a full future backing data - PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(backing: SwiftData.PersistentIdentifier.PersistentIdentifierBacking.managedObjectID(0x9872c0007ba42159 ))) with Optional(7639D151-5D48-46AC-AB2A-7F0F50919AC5) But I guess it's a different kind of problem now.
Aug ’25
Reply to Change to safe area logic on iOS 26
it would be helpful to see a small test project that has the relationship between your navigation toolbar and the content view set up the same way as your real app and see if you get the same results. If so, please provide a link to that test project. — Ed Ford,  DTS Engineer
Topic: UI Frameworks SubTopic: UIKit
Aug ’25
Reply to How do you observe the count of records in a Swift Data relationship?
There are some subtle things that determine if a change on a SwiftData model is observable, as discussed in this WWDC25 session (starting from around 14:00.) Your code snippet doesn't show where the folder in FolderView is from and how you add a new item. If you can share a runnable code snippet that demonstrates the issue, I'd be able to figure out why folder doesn't trigger an update. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’25
Reply to Is realtime multidevice persistence possible using SwiftData?
Even though this doesn’t provide a direct solution for cross-device real-time database persistence, it may simulate the behavior you’re looking for. If both devices are on the same network, you can leverage the MultipeerConnectivity framework to send data to other devices immediately and then persist it locally. This way you can achieve a “live update” experience within the Apple ecosystem, while still using SwiftData for storage.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’25
Is realtime multidevice persistence possible using SwiftData?
I really enjoyed using SwiftData for persistence until I found out that the CloudKit integration ensures changes are only eventually consistent, and that changes can propagate to other devices after as long as minutes, making it useless for any feature that involves handoff between devices. Devastating news but I guess it’s on me for nrtfm. I may try my hand at a custom model context DataStore integrating Powersync, but that’s a whole trip and before I embark on it I was wondering if anyone had suggestions for resolving this problem in a simple and elegant manager that allows me to keep as much of the machinery within Apple’s ecosystem as possible, while ensure reliable “live” updates to SwiftData stores on all eligible devices.
Replies
2
Boosts
0
Views
230
Activity
Aug ’25
SwiftData CloudKit hangs on Active scene Phase
If Cloudkit is enabled, SwiftData @Query operation hangs when the View scenePhase becomes active. Seems like the more @Query calls you have, the more it hangs. This has been first documented some time ago, but in typical Apple style, it has not been addressed or even commented on. https://developer.apple.com/forums/thread/761434
Replies
1
Boosts
0
Views
214
Activity
Aug ’25
SwiftData and CloudKit
Recently I've been working on a demo project called iLibrary. The main goal was to learn more about CloudKit and SwiftData. After a while I noticed that there were some hangs/freezes when running the app in debug mode. I first tried this with Xcode 15.4 and iOS 17.5. Here the hang only appears at the beginning, but only for a few seconds. But when I exit debug mode, there are no more hangs. With Xcode 16 beta 4 and iOS 18 it looks completely different. In this case, the hangs and freezes are always present, whether in debug mode or not. And it's not just at the beginning, it's throughout the app. I'm aware that this is still a beta, but I still find this weird. And when I profile this I see that the main thread gets quite overloaded. Interestingly, my app doesn't have that many operations going on. So I guess something with the sync of SwiftData or my CloudKitManger where I fetch some records from the public database is not running fine. Lastly, I wanted to delete the iCloud app data. So I w
Replies
9
Boosts
0
Views
1.8k
Activity
Aug ’25
Reply to SwiftData and CloudKit
The original post had been a year ago, and had run out of my radar since then, until this new post brought this back, thanks to @jenyalebid. If simply creating a SwiftData model container with CloudKit integration, which kicks off the initialization of NSPersistentCloudKitContainer under the hood, causes the hang, I'd suggest that you start with filing an actionable feedback report, because the initialization is not supposed to be a long task. SwiftData + CloudKit integration is based on NSPersistentCloudKitContainer, and so folks can follow the tips described in the following technote to analyze if there is anything goes wrong in the initialization phase: TN3163: Understanding the synchronization of NSPersistentCloudKitContainer If somebody can share a minimal project, with detailed steps, that reproduces the issue, I'd be able to take a look as well. The orignal post does contain a link, but it has been a year, and I am not sure if the issue is the same. Best, —— Ziqiao Chen  Worldwide De
Replies
Boosts
Views
Activity
Aug ’25
Reply to Is realtime multidevice persistence possible using SwiftData?
I don't have a lot to say about implementing a real-time data persistence system cross devices, but just to confirm that CloudKit isn't a real-time system, and so SwiftData / Core Data + CloudKit integration is not real time either, as you have found out. To optimize the overall experience, CloudKit even implemented a mechanism to throttle requests, if the rate is too high, as discussed in TN3162: Understanding CloudKit throttles. And yes, a custom data store will be the way to go, if you would use SwiftData. You need to take care the real-time synchronization part when going along this path. There is no system-provided framework specifically for that purpose. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’25
App extension write data The main target reads data.
I have an iOS app with a main target and an app extension. I want the app extension to write data to the SwiftData in App Groups, while the main target reads the data. However, currently, the app extension only has permission to read data, not to write it.Is the issue due to my incorrect configuration or an Apple-imposed restriction?
Replies
2
Boosts
0
Views
123
Activity
Aug ’25
Reply to SwiftData and CloudKit
Could anyone from Apple weigh in on this? this is a real and easily reproducible issue. on active scenePhase, if CloudKit, specially SwiftData, is enabled… there is a noticeable hang first few seconds. I am assuming it has to do with the @Query sync with remote.
Replies
Boosts
Views
Activity
Aug ’25
Reply to How do I use IOUserSCSIPeripheralDeviceType00?
So, the first thing to understand here is that the IOKitPersonalities is called that because it IS in fact a fully valid IOKitPersonalities dictionary. That is, what the system actually uses that dictionary for is: Perform a standard IOKit match and load cycle in the kernel. The final driver in the kernel then uses the DEXT-specific data to launch and run your DEXT process outside the kernel. So, working through the critical keys in that dictionary: IOProviderClass-> This is the in-kernel class that your driver loads on top of. In your case, that would be IOSCSIPeripheralDeviceNub or one of its variants. IOClass-> This is the in-kernel class that your driver loads on top of. This is where things can become a bit confused, as some families work by: Routing all activity through the provider reference so that the DEXT-specific class does not matter (PCIDriverKit). Having the DEXT subclass a specific subclass which corresponds to a specific kernel driver (SCSIPeripheralsDriverKit). This distinction is descr
Replies
Boosts
Views
Activity
Aug ’25
Reply to SwiftData Inheritance Query Specialized Model
Nice to know that the original issue goes away in the latest Beta. Regarding the crash triggered by the access to Item.children, if you can provide a runnable code snippet to demo the issue, I'll take another look. You have mentioned a few classes with inheritance, and so I think it is probably worth mentioning that over-using inheritance may impact your app's performance negatively. Concretely, with today's default store (DefaultStore), all the types in an inheritance hierarchy are persisted with one single table in SQLite. If your inheritance hierarchy has many classes, the table (columns and data) can be quite big, which can slow down the performance of fetching and inserting data. That being said, when adopting SwiftData inheritance, you might examine if that is a right use case. This WWDC25 session(starting from around 4:25) covers this topic a bit. You can take a look, if haven't yet. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Aug ’25
Reply to RCS firewall domains & ports
I’m not sure of your relationship to niggeulimann, but I responded to their copy of this question over on this thread. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = eskimo + 1 + @ + apple.com
Replies
Boosts
Views
Activity
Aug ’25
Equatable with default actor isolation of MainActor
I filed the following issue on swiftlang/swift on GitHub (Aug 8th), and a followup the swift.org forums, but not getting any replies. As we near the release of Swift 6.2, I want to know if what I'm seeing below is expected, or if it's another case where the compiler needs a fix. protocol P1: Equatable { } struct S1: P1 { } // Error: Conformance of 'S1' to protocol 'P1' crosses into main actor-isolated code an can cause data races struct S1Workaround: @MainActor P1 { } // OK // Another potential workaround if `Equatable` conformance can be moved to the conforming type. protocol P2 { } struct S2: Equatable, P2 { } // OK There was a prior compiler bug fix which addressed inhereted protocols regarding @MainActor. For Equatable, one still has to use @MainActoreven when the default actor isolation is MainActor. Also affects Hashable and any other protocol inheriting from Equatable.
Replies
3
Boosts
0
Views
1.2k
Activity
Aug ’25
Reply to SwiftData Inheritance Query Specialized Model
Hi Ziqiao, I've tried with iOS 26 Beta 7 and since Beta 8 (landed tonight) on device (because my Xcode is stuck on iOS Beta 6, don't know why) and the problem is solved. I can now query CollectionItem with predicate that contains inherited properties. Now I have only got problems with accesses to the children property in List. When i got the following hierarchy and the SwiftUI view List access to the Item.children property I got another kind of crash. Category: Work (parent: none) Category: Tech (parent: Work) Thread 1: Fatal error: Never access a full future backing data - PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(backing: SwiftData.PersistentIdentifier.PersistentIdentifierBacking.managedObjectID(0x9872c0007ba42159 ))) with Optional(7639D151-5D48-46AC-AB2A-7F0F50919AC5) But I guess it's a different kind of problem now.
Replies
Boosts
Views
Activity
Aug ’25
Reply to Change to safe area logic on iOS 26
it would be helpful to see a small test project that has the relationship between your navigation toolbar and the content view set up the same way as your real app and see if you get the same results. If so, please provide a link to that test project. — Ed Ford,  DTS Engineer
Topic: UI Frameworks SubTopic: UIKit
Replies
Boosts
Views
Activity
Aug ’25
Reply to How do you observe the count of records in a Swift Data relationship?
There are some subtle things that determine if a change on a SwiftData model is observable, as discussed in this WWDC25 session (starting from around 14:00.) Your code snippet doesn't show where the folder in FolderView is from and how you add a new item. If you can share a runnable code snippet that demonstrates the issue, I'd be able to figure out why folder doesn't trigger an update. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’25