Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

Reply to How to correctly fetch data using SwiftData
My code for the last block: import SwiftUI import SwiftData struct HomeView: View { @Query var profiledata: [allProfileData] //get all profiledata @Environment(.modelContext) private var modelContext @State private var profileImage: Image = Image(DefaultProfile) var body: some View { VStack { profileImage } .onAppear() { let fetchRequest = FetchDescriptor() let fetchedData = try? modelContext.fetch(fetchRequest) print(Fetched count: (fetchedData?.count ?? 0)) if let imageData = profiledata.first?.profileImageData, let uiImage = UIImage(data: imageData) { profileImage = Image(uiImage: uiImage) } else { profileImage = Image(DefaultProfile) } //yes, I realize that I could use profiledata.first?.profileImage but I was just checking if profileImageData would save or not } } }
Topic: UI Frameworks SubTopic: General Tags:
Nov ’25
Reply to How to sending capability requests.
I have a new question: I include Capabilities in the Provisioning Profile that might not be used, just in case. If I don't list all these Capabilities in the driver's Entitlements, will it cause the driver to behave abnormally? No, this doesn't affect anything. I then created a UserClient inheriting from the IOUserClient class to access it from the app, but IOServiceOpen fails with code 0xe00002d7 and cannot open. Huh. So, 0xe00002d7 is kIOReturnOffline, but I'm not sure how you'd get it from IOServiceOpen. It's returned in a few places in DriverKit and xnu, but none of them look like places you'd reach from IOServiceOpen. My best guess is that you're either trying to open the wrong object or your subclass is in an odd/unexpected state which is making it non-connectable. If you haven't already, make sure you check the system log as it's possible we logged additional info about what actually happened. Actually... real-time correction of myself: And in the driver's Info.plist, the following definitions
Nov ’25
A crash occurs when fetching history when Model has preserveValueOnDeletion attribute and using inheritance
Hello, In our app, we’ve modeled our schema using inheritance introduced in iOS 26.0, and we’re implementing SwiftData History to re-fetch models only when necessary. @Model public class Transaction { @Attribute(.preserveValueOnDeletion) public var date: Date = Date() public var amount: Double = 0 public var memo: String? } @Model public final class Spending: Transaction { public var installmentIndex: Int = 1 public var installment: Int = 1 public var installmentID: UUID? } If data has been deleted from database, we need to check a date property to determine whether to re-fetch datas. To do this, we added the preserveValueOnDeletion attribute to date property so we could retrieve it from the History tombstone value. However, after adding this attribute, a crash occurs. There is a console log Could not cast value of type 'Swift.ReferenceWritableKeyPath' (0x106bf8328) to 'Swift.PartialKeyPath' (0x1094f21d8). and error log attached StrictMoneyChecking-2025-11-07-105108.txt I also tried this in
1
0
298
Nov ’25
Reply to How to sending capability requests.
I understand that it is not necessary to include this com.apple.developer.driverkit.allow-any-userclient-access in the driver's Entitlements. I have a new question: I include Capabilities in the Provisioning Profile that might not be used, just in case. If I don't list all these Capabilities in the driver's Entitlements, will it cause the driver to behave abnormally? To issue vendor-specific commands, I created a driver class inheriting from the IOUserSCSIPeripheralDeviceType00 class in the SCSIPeripheralDriverKit Framework. I then created a UserClient inheriting from the IOUserClient class to access it from the app, but IOServiceOpen fails with code 0xe00002d7 and cannot open. The driver's entitlements are as follows. com.apple.developer.driverkit.transport.usb com.apple.developer.driverkit.family.scsicontroller com.apple.developer.driverkit.communicates-with-drivers com.apple.developer.driverkit.allow-third-party-userclients com.apple.developer.driverkit And in the driver's Info.plist
Nov ’25
Correct SwiftData Concurrency Logic for UI and Extensions
Hi everyone, I'm looking for the correct architectural guidance for my SwiftData implementation. In my Swift project, I have dedicated async functions for adding, editing, and deleting each of my four models. I created these functions specifically to run certain logic whenever these operations occur. Since these functions are asynchronous, I call them from the UI (e.g., from a button press) by wrapping them in a Task. I've gone through three different approaches and am now stuck. Approach 1: @MainActor Functions Initially, my functions were marked with @MainActor and worked on the main ModelContext. This worked perfectly until I added support for App Intents and Widgets, which caused the app to crash with data race errors. Approach 2: Passing ModelContext as a Parameter To solve the crashes, I decided to have each function receive a ModelContext as a parameter. My SwiftUI views passed the main context (which they get from @Environment(.modelContext)), while the App Intents and Widgets created and pas
5
0
332
Nov ’25
Reply to SwiftData not loading under iOS 26.1
Oh, that will be a serious issue, and we need to reproducible case to investigate. Would you mind to file a feedback report with a project + the prepared SwiftData store file + the steps to reproduce the issue for us, and share your report ID here? Thanks! Best, —— Ziqiao Chen  Worldwide Developer Relations.
Nov ’25
Reply to Xcode 26.1 / OS 26.1 regression with schema and macros
Please allow me to make sure I understand correctly: Are you saying that Xcode 26.1 automatically changes your code by adding @Attribute(.transformable) for your SwiftData properties with array collection types? If that's the case, would you mind to file a feedback report with the code before and after the change for us, and share your report ID here? Thanks! Best, —— Ziqiao Chen  Worldwide Developer Relations.
Nov ’25
Crashes because main actor isolated closures are called on a background thread with `DispatchGroup.notify`, but no compiler warnings
Hello! We are in the progress of migrating a large Swift 5.10 legacy code base over to use Swift 6.0 with Strict Concurrency checking. We have already stumbled across a few weird edge cases where the guaranteed @MainActor isolation is violated (such as with @objc #selector methods used with NotificationCenter). However, we recently found a new scenario where our app crashes accessing main actor isolated state on a background thread, and it was surprising that the compiler couldn't warn us. Minimal reproducible example: class ViewController: UIViewController { var isolatedStateString = Some main actor isolated state override func viewDidLoad() { exampleMethod() } /// Note: A `@MainActor` isolated method in a `@MainActor` isolated class. func exampleMethod() { testAsyncMethod() { [weak self] in // !!! Crash !!! MainActor.assertIsolated() // This callback inherits @MainActor from the class definition, but it is called on a background thread. // It is an error to mutate main actor isolated state off the
3
0
669
Nov ’25
iOS Multiple BSSID Parsing/Inherit Behavior Issue – HS2.0 IE Handling Incorrect (Non‑Tx VAP should not inherit Tx VAP’s HS2.0 Indication)
I am experiencing issue - iphone16/17 can't connect to the non-txvap SSID when the corresponding txvap is passpoint SSID. It may always fail to connect. But when I set the non-passpoint SSID as txvap and passpoint SSID as non-txvap, then iPhone16/17 can connect to the two SSID successfully. iPhone will add “HS20=1” flag for the non-passpoint SSID, then iPhone will ALWAYS not connect that SSID successfully. Please see the log below I captured from the issue iPhone. -[WFNetworkListController _updateViewControllerScanResults]_block_invoke: removing associationCtx network from scan results See detail in FB20923870 Is there anybody else meet this issue?
1
0
47
Nov ’25
Is that possible to update ModelContainer?
Here is what I thought I want to give each user a unique container, when the user login or register, the user could isolate their data in specific container. I shared the container in a singleton actor, I found it's possible to update the container in that actor. But I think it won't affect the modelContext which is in the Environment. Does SwiftData allow me or recommend to do that?
4
0
226
Nov ’25
Reply to CloudKit - moving record objects between zones
If you are using SwiftData + CloudKit, which is based on NSPersistentCloudKitContainer, it doesn't support cross-share relationships, and so you can't have a collection in one zone and a relationship of the collection (a sub-collection, for example) in another. This is mentioned in here: NSPersistentCloudKitContainer doesn’t support cross-share relationships. That is, it doesn’t allow relating objects associated with different shares. When sharing an object, NSPersistentCloudKitContainer moves the entire object graph, which includes the object and all its relationships, to the share’s record zone. If you are using the CloudKit framework directly, the source and target objects of CKRecord.Reference must be in the same zone of the same database, and so you will need to maintain the relationship with your own logic. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: Community SubTopic: Apple Developers Tags:
Nov ’25
CloudKit - moving record objects between zones
My app has three main SwiftData models: Collection, SavedItem, and Extract. A Collection can contain subcollections (folders within folders) and SavedItems (files). Each SavedItem can have child Extracts. I'm preparing for the ability for users to be able to share Collections with each other. Currently, my architecture treats each Collection as the root of its own CloudKit zone (a root parent Collection and all of its items and subcollections live in 1 zone). This makes sharing and isolation straightforward, but it also means that moving a SavedItem or subcollection between Collections involves moving it across zones. I’m trying to figure out the best pattern for handling these cross-zone moves while keeping data integrity, relationships, and sharing intact. My understanding is that in CloudKit, and moving a record from Zone A to Zone B would require deleting it from Zone A and recreating it in Zone B - while somehow maintaining the link back to my local SwiftData store. Has anyone
3
0
387
Nov ’25
Reply to SwiftData not loading under iOS 26.1
That is a migration error, which happens when you change your SwiftData models in a way unsupported by lightweight migration. You can probably start with reviewing the changes you made on your SwiftData models, if any. For more information about how to evolve your SwiftData schema, see this WWDC session. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Nov ’25
iOS 26.1 and SwiftData: Can't reuse store?
I have one target building and filling the SwiftData store and then copying the same store file to another target of the app to use the contents. That worked fine from iOS 17 to iOS 26.0.1 Under iOS 26.1 I am getting following error: CoreData: error: This store file was previously used on a build with Persistence-1522 but is now running on a build with Persistence-1518. file:///Users/xxx/Library/Developer/CoreSimulator/Devices/0FE92EA2-57FA-4A5E-ABD0-DAB4DABC3E02/data/Containers/Data/Application/B44D3256-9B09-4A60-94E2-C5F11A6519E7/Documents/default.store What does it mean and how to get back to working app under iOS 26.1?
1
0
264
Nov ’25
Reply to How to correctly fetch data using SwiftData
My code for the last block: import SwiftUI import SwiftData struct HomeView: View { @Query var profiledata: [allProfileData] //get all profiledata @Environment(.modelContext) private var modelContext @State private var profileImage: Image = Image(DefaultProfile) var body: some View { VStack { profileImage } .onAppear() { let fetchRequest = FetchDescriptor() let fetchedData = try? modelContext.fetch(fetchRequest) print(Fetched count: (fetchedData?.count ?? 0)) if let imageData = profiledata.first?.profileImageData, let uiImage = UIImage(data: imageData) { profileImage = Image(uiImage: uiImage) } else { profileImage = Image(DefaultProfile) } //yes, I realize that I could use profiledata.first?.profileImage but I was just checking if profileImageData would save or not } } }
Topic: UI Frameworks SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’25
Reply to Drag & Drop with view hierarchy
Finally I was able to solve this via GeometryProxy with some math. It could be hard to wrap the brain around local and global coordinates relationship.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Nov ’25
Reply to How to sending capability requests.
I have a new question: I include Capabilities in the Provisioning Profile that might not be used, just in case. If I don't list all these Capabilities in the driver's Entitlements, will it cause the driver to behave abnormally? No, this doesn't affect anything. I then created a UserClient inheriting from the IOUserClient class to access it from the app, but IOServiceOpen fails with code 0xe00002d7 and cannot open. Huh. So, 0xe00002d7 is kIOReturnOffline, but I'm not sure how you'd get it from IOServiceOpen. It's returned in a few places in DriverKit and xnu, but none of them look like places you'd reach from IOServiceOpen. My best guess is that you're either trying to open the wrong object or your subclass is in an odd/unexpected state which is making it non-connectable. If you haven't already, make sure you check the system log as it's possible we logged additional info about what actually happened. Actually... real-time correction of myself: And in the driver's Info.plist, the following definitions
Replies
Boosts
Views
Activity
Nov ’25
A crash occurs when fetching history when Model has preserveValueOnDeletion attribute and using inheritance
Hello, In our app, we’ve modeled our schema using inheritance introduced in iOS 26.0, and we’re implementing SwiftData History to re-fetch models only when necessary. @Model public class Transaction { @Attribute(.preserveValueOnDeletion) public var date: Date = Date() public var amount: Double = 0 public var memo: String? } @Model public final class Spending: Transaction { public var installmentIndex: Int = 1 public var installment: Int = 1 public var installmentID: UUID? } If data has been deleted from database, we need to check a date property to determine whether to re-fetch datas. To do this, we added the preserveValueOnDeletion attribute to date property so we could retrieve it from the History tombstone value. However, after adding this attribute, a crash occurs. There is a console log Could not cast value of type 'Swift.ReferenceWritableKeyPath' (0x106bf8328) to 'Swift.PartialKeyPath' (0x1094f21d8). and error log attached StrictMoneyChecking-2025-11-07-105108.txt I also tried this in
Replies
1
Boosts
0
Views
298
Activity
Nov ’25
Reply to How to sending capability requests.
I understand that it is not necessary to include this com.apple.developer.driverkit.allow-any-userclient-access in the driver's Entitlements. I have a new question: I include Capabilities in the Provisioning Profile that might not be used, just in case. If I don't list all these Capabilities in the driver's Entitlements, will it cause the driver to behave abnormally? To issue vendor-specific commands, I created a driver class inheriting from the IOUserSCSIPeripheralDeviceType00 class in the SCSIPeripheralDriverKit Framework. I then created a UserClient inheriting from the IOUserClient class to access it from the app, but IOServiceOpen fails with code 0xe00002d7 and cannot open. The driver's entitlements are as follows. com.apple.developer.driverkit.transport.usb com.apple.developer.driverkit.family.scsicontroller com.apple.developer.driverkit.communicates-with-drivers com.apple.developer.driverkit.allow-third-party-userclients com.apple.developer.driverkit And in the driver's Info.plist
Replies
Boosts
Views
Activity
Nov ’25
Correct SwiftData Concurrency Logic for UI and Extensions
Hi everyone, I'm looking for the correct architectural guidance for my SwiftData implementation. In my Swift project, I have dedicated async functions for adding, editing, and deleting each of my four models. I created these functions specifically to run certain logic whenever these operations occur. Since these functions are asynchronous, I call them from the UI (e.g., from a button press) by wrapping them in a Task. I've gone through three different approaches and am now stuck. Approach 1: @MainActor Functions Initially, my functions were marked with @MainActor and worked on the main ModelContext. This worked perfectly until I added support for App Intents and Widgets, which caused the app to crash with data race errors. Approach 2: Passing ModelContext as a Parameter To solve the crashes, I decided to have each function receive a ModelContext as a parameter. My SwiftUI views passed the main context (which they get from @Environment(.modelContext)), while the App Intents and Widgets created and pas
Replies
5
Boosts
0
Views
332
Activity
Nov ’25
Reply to SwiftData not loading under iOS 26.1
Oh, that will be a serious issue, and we need to reproducible case to investigate. Would you mind to file a feedback report with a project + the prepared SwiftData store file + the steps to reproduce the issue for us, and share your report ID here? Thanks! Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Nov ’25
Reply to Xcode 26.1 / OS 26.1 regression with schema and macros
Please allow me to make sure I understand correctly: Are you saying that Xcode 26.1 automatically changes your code by adding @Attribute(.transformable) for your SwiftData properties with array collection types? If that's the case, would you mind to file a feedback report with the code before and after the change for us, and share your report ID here? Thanks! Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Nov ’25
Crashes because main actor isolated closures are called on a background thread with `DispatchGroup.notify`, but no compiler warnings
Hello! We are in the progress of migrating a large Swift 5.10 legacy code base over to use Swift 6.0 with Strict Concurrency checking. We have already stumbled across a few weird edge cases where the guaranteed @MainActor isolation is violated (such as with @objc #selector methods used with NotificationCenter). However, we recently found a new scenario where our app crashes accessing main actor isolated state on a background thread, and it was surprising that the compiler couldn't warn us. Minimal reproducible example: class ViewController: UIViewController { var isolatedStateString = Some main actor isolated state override func viewDidLoad() { exampleMethod() } /// Note: A `@MainActor` isolated method in a `@MainActor` isolated class. func exampleMethod() { testAsyncMethod() { [weak self] in // !!! Crash !!! MainActor.assertIsolated() // This callback inherits @MainActor from the class definition, but it is called on a background thread. // It is an error to mutate main actor isolated state off the
Replies
3
Boosts
0
Views
669
Activity
Nov ’25
iOS Multiple BSSID Parsing/Inherit Behavior Issue – HS2.0 IE Handling Incorrect (Non‑Tx VAP should not inherit Tx VAP’s HS2.0 Indication)
I am experiencing issue - iphone16/17 can't connect to the non-txvap SSID when the corresponding txvap is passpoint SSID. It may always fail to connect. But when I set the non-passpoint SSID as txvap and passpoint SSID as non-txvap, then iPhone16/17 can connect to the two SSID successfully. iPhone will add “HS20=1” flag for the non-passpoint SSID, then iPhone will ALWAYS not connect that SSID successfully. Please see the log below I captured from the issue iPhone. -[WFNetworkListController _updateViewControllerScanResults]_block_invoke: removing associationCtx network from scan results See detail in FB20923870 Is there anybody else meet this issue?
Replies
1
Boosts
0
Views
47
Activity
Nov ’25
Is that possible to update ModelContainer?
Here is what I thought I want to give each user a unique container, when the user login or register, the user could isolate their data in specific container. I shared the container in a singleton actor, I found it's possible to update the container in that actor. But I think it won't affect the modelContext which is in the Environment. Does SwiftData allow me or recommend to do that?
Replies
4
Boosts
0
Views
226
Activity
Nov ’25
Reply to CloudKit - moving record objects between zones
If you are using SwiftData + CloudKit, which is based on NSPersistentCloudKitContainer, it doesn't support cross-share relationships, and so you can't have a collection in one zone and a relationship of the collection (a sub-collection, for example) in another. This is mentioned in here: NSPersistentCloudKitContainer doesn’t support cross-share relationships. That is, it doesn’t allow relating objects associated with different shares. When sharing an object, NSPersistentCloudKitContainer moves the entire object graph, which includes the object and all its relationships, to the share’s record zone. If you are using the CloudKit framework directly, the source and target objects of CKRecord.Reference must be in the same zone of the same database, and so you will need to maintain the relationship with your own logic. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: Community SubTopic: Apple Developers Tags:
Replies
Boosts
Views
Activity
Nov ’25
CloudKit - moving record objects between zones
My app has three main SwiftData models: Collection, SavedItem, and Extract. A Collection can contain subcollections (folders within folders) and SavedItems (files). Each SavedItem can have child Extracts. I'm preparing for the ability for users to be able to share Collections with each other. Currently, my architecture treats each Collection as the root of its own CloudKit zone (a root parent Collection and all of its items and subcollections live in 1 zone). This makes sharing and isolation straightforward, but it also means that moving a SavedItem or subcollection between Collections involves moving it across zones. I’m trying to figure out the best pattern for handling these cross-zone moves while keeping data integrity, relationships, and sharing intact. My understanding is that in CloudKit, and moving a record from Zone A to Zone B would require deleting it from Zone A and recreating it in Zone B - while somehow maintaining the link back to my local SwiftData store. Has anyone
Replies
3
Boosts
0
Views
387
Activity
Nov ’25
Reply to SwiftData not loading under iOS 26.1
That is a migration error, which happens when you change your SwiftData models in a way unsupported by lightweight migration. You can probably start with reviewing the changes you made on your SwiftData models, if any. For more information about how to evolve your SwiftData schema, see this WWDC session. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Nov ’25
iOS 26.1 and SwiftData: Can't reuse store?
I have one target building and filling the SwiftData store and then copying the same store file to another target of the app to use the contents. That worked fine from iOS 17 to iOS 26.0.1 Under iOS 26.1 I am getting following error: CoreData: error: This store file was previously used on a build with Persistence-1522 but is now running on a build with Persistence-1518. file:///Users/xxx/Library/Developer/CoreSimulator/Devices/0FE92EA2-57FA-4A5E-ABD0-DAB4DABC3E02/data/Containers/Data/Application/B44D3256-9B09-4A60-94E2-C5F11A6519E7/Documents/default.store What does it mean and how to get back to working app under iOS 26.1?
Replies
1
Boosts
0
Views
264
Activity
Nov ’25