Search results for

“SwiftData inheritance relationship”

4,986 results found

Post

Replies

Boosts

Views

Activity

Accessory View Not Displayed When Switching Input Methods via Bluetooth Keyboard
Hello everyone, When I press Control + Space on my Bluetooth keyboard to trigger input method switching, the accessory view fails to appear. This prevents me from quickly identifying the current input method type. Upon inspecting the View Hierarchy, I noticed that UICursorAccessoryView is not being created. For context, my input method responder inherits from UIResponder and conforms to the UITextInputTraits, UIKeyInput, and UITextInput protocols. The accessory view displays normally during accented input and Chinese input. Could you please guide me on how to troubleshoot this issue?
4
0
534
Jan ’26
Naming Collision Between Model Attribute and Enum Case in SwiftData and CloudKit
There is a conflict in SwiftData (specifically when synced with CloudKit) when a @Model attribute shares the same name as a case within its assigned enum type. When this occurs, accessing the attribute on a model instance consistently returns the value corresponding to the enum case name, rather than the actual value persisted in the database. Steps to Reproduce Define an enumeration (e.g., Status) with a case that matches a planned property name (e.g., case status). Create a SwiftData @Model that uses this enum. Name the property in the model the same as the enum case. Attempt to save and then retrieve the value. Example Code enum TaskStatus: String, Codable { case status // The conflict source case pending case completed } @Model class TodoItem { // Conflict: Property name matches enum case name var status: TaskStatus init(status: TaskStatus) { self.status = status } } Expected Behavior The property item.status should return the value stored in the database (e.g., .pending or .completed).
2
0
101
Jan ’26
DNS Proxy system extension – OSSystemExtensionErrorDomain error 9 “validationFailed” on clean macOS machine
Hi, I’m implementing a macOS DNS Proxy as a system extension and running into a persistent activation error: OSSystemExtensionErrorDomain error 9 (validationFailed) with the message: extension category returned error This happens both on an MDM‑managed Mac and on a completely clean Mac (no MDM, fresh install). Setup macOS: 15.x (clean machine, no MDM) Xcode: 16.x Team ID: AAAAAAA111 (test) Host app bundle ID: com.example.agent.NetShieldProxy DNS Proxy system extension bundle ID: com.example.agent.NetShieldProxy.dnsProxy The DNS Proxy is implemented as a NetworkExtension system extension, not an app extension. Host app entitlements From codesign -d --entitlements :- /Applications/NetShieldProxy.app: xml com.apple.application-identifier AAAAAAA111.com.example.agent.NetShieldProxy com.apple.developer.system-extension.install com.apple.developer.team-identifier AAAAAAA111 com.apple.security.app-sandbox com.apple.security.application-groups group.com.example.NetShieldmac com.apple.security.files.user-selected.
9
0
420
Jan ’26
Reply to evaluatedPolicyDomainState
I’m not sure what sort of help you’re expecting me to provide here. As I mentioned above, this looks like a bug to me. If I had a bug report with a sysdiagnose log, I might — and I want to stress the might here — be able to offer more insight. But without that, I’m flying completely blind. In terms of a workaround, I see two potential options: You could explore user-level workarounds with your user. For example: You might have them reset Face ID (Settings > Face ID & Passcode > Reset Face ID) and re-enroll. Or have them disable the device passcode and then re-enable it. Or have them back up their device and restore from that backup. All of these things are common patterns for clearing out mysterious problems. You could explore code-level workarounds. For example: You might change your system to record multiple biometric domain states. Or have an option to disable biometric domain state checking for specific users. It’s hard to offer specific advice on either of these fronts because I don’t have a relationship
Topic: Privacy & Security SubTopic: General Tags:
Jan ’26
Reply to Unable to sync SwiftData model fully using CloudKit
The following console log says that your app detected an account switching at the beginning of the launch process, which may erase the existing data created before the switching. It also says that you were using a simulator. CoreData: warning: CoreData+CloudKit: -[PFCloudKitSetupAssistant _checkUserIdentity:]_block_invoke_3(1487): : CKIdentity record has changed from _b09f3f2b1357d21fdd823f58762f6077 to _4e8dc229775b034192825a3081a709a4 error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(1242): : Failed to set up CloudKit integration for store: (URL: file:///Users/yuanping_ke/Library/Developer/CoreSimulator/Devices/BA9191E9-6DB4-4A30-9196-0A6C06A11F2E/data/Containers/Data/Application/5977FE0D-50D4-4AE0-8134-5D8B0B662298/Library/Application%20Support/default.store) Later your app did successfully set up CloudKit integration, as shown below, and then did several successful exports and imports, but it seems that there is no change merged into the store. CoreData: warning:
Jan ’26
Unable to sync SwiftData model fully using CloudKit
Hey everyone I just ran into an issue where I couldn't sync the model below fully by using CloudKit, enum LinkMapV3_1: VersionedSchema { static let versionIdentifier: Schema.Version = .init(3, 1, 0) static var models: [any PersistentModel.Type] { [AnnotationData.self, GroupData.self, Item.self, Deployment.self, History.self] } // MARK: - Data @Model class AnnotationData { var name: String = var longitude: Double = 0.0 var latitude: Double = 0.0 var order: Int = -1 var level: Int = 1 var detail: String = @Relationship(deleteRule: .nullify, inverse: GroupData.annotation) var groups: [GroupData]? @Relationship(deleteRule: .nullify, inverse: AnnotationData.to) var from: AnnotationData? var to: AnnotationData? var history: History? } // MARK: - History @Model class History { var id: UUID = UUID() var timestamp: Date = Date() @Relationship(deleteRule: .nullify, inverse: AnnotationData.history) var annotations: [AnnotationData]? @Relationship(deleteRule: .nullify, inverse: Group
1
0
300
Jan ’26
Reply to @ComputedProperty vs copying values SwiftData AppEntity
A @Property variable is computed when the app entity (AppEntity) is initialized, while a @ComputedProperty variable is computed when the entity is returned. So yes, the SwiftData model can become stale if it changes after the app entity is initialized. Assuming that you have a data controller that manages your SwiftData models, I'd think that you can make the SwiftData model associated with the app entity up to date, so that the getters of your @ComputedProperty variables can return the value directly (without doing a fetch). To ensure the SwiftData model is up to date, you might need to observe the notifications triggered by a store change (basically NSManagedObjectContextObjectsDidChange and .NSPersistentStoreRemoteChange, assuming you are using DefaultStore), check if the change is relevant, and re-fetch the data as needed. If you need more discussion on this topic, feel free to follow up with more details about how your SwiftData store may change, Best, —— Ziqi
Jan ’26
@ComputedProperty vs copying values SwiftData AppEntity
I'm setting up App Entities for my SwiftData models and I'm not sure about the best way to reference SwiftData model properties in the AppEntity. I have a SwiftData model with many properties: @Model final class Contact { @Attribute(.unique) var id: UUID = UUID() var name: String var phoneNumber: String var email: String var website: URL? var birthday: Date? var notes: String // ... many more properties } I want to expose these properties on my AppEntity so they're available for system features, such as giving Apple Intelligence more context about on-screen content. struct ContactEntity: AppEntity { var id: UUID @Property(title: Name) var name: String @Property(title: Phone) var phoneNumber: String @Property(title: Email) var email: String // ... all the other properties } I couldn't find guidance in the documentation for this specific situation. I've considered two approaches: Add @Property variables to the AppEntity for each SwiftData model property and copy all values fr
1
0
149
Jan ’26
Reply to Deleting Production Database SwiftData
Just to add that a code snippet showing how to add multiple SwiftData model configurations to a model container is shown here. Also, this technote talks about how to work with default data. It covers Core Data and hasn't been updated, but the main idea, which I believe is worth mentioning, applies to SwiftData apps as well. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’26
Deleting Production Database SwiftData
Hi all, I have setup my app to use SwiftData with CloudKit sync. I have a production environment and development environment. I can reset the development environment for myself and all users in CloudKit console, but I can't reset the production one as it's tried to users' iCloud accounts, so I've added a button in-app for that feature. In the onboarding of my app, I pre-seed the DB with some default objects, which should be persisted between app install. The issue I'm running into is that I'm unable to force-pull these models from iCloud during the onboarding of a clean re-install, which leads to the models later appearing as duplicates once the user has been on the app for a few minutes and it has pulled from their iCloud account. If anyone has any suggestions on how to handle this issue, I would greatly appreciate it.
2
0
273
Jan ’26
Handling Context Save Errors
I was wondering if errors are common for the code below for saving SwiftData data and what would be the best way to handle them (popup, closing the app)? do { try modelContext.save() } catch { print(error) }
Topic: Design SubTopic: General Tags:
1
0
286
Jan ’26
SwiftData & CloudKit: Arrays of Codable Structs Causing NSKeyedUnarchiveFromData Error
I have SwiftData models containing arrays of Codable structs that worked fine before adding CloudKit capability. I believe they are the reason I started seeing errors after enabling CloudKit. Example model: @Model final class ProtocolMedication { var times: [SchedulingTime] = [] // SchedulingTime is Codable // other properties... } After enabling CloudKit, I get this error logged to the console: 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release CloudKit Console shows this times data as plain text instead of bplist format. Other struct/enum properties display correctly (I think) as bplist in CloudKit Console. The local SwiftData storage handled these arrays fine - this issue only appeared with CloudKit integration. What's the recommended approach for storing arrays of Codable structs in SwiftData models that sync with CloudKit?
8
0
933
Jan ’26
Performance in Large Datasets (SwiftUI+SwiftData app)
Hi everyone, In the simple app below, I have a QueryView that has LazyVStack containing 100k TextField's that edit the item's content. The items are fetched with a @Query. On launch, the app will generate 100k items. Once created, when I press any of the TextField's , a severe hang happens, and every time I type a single character, it will cause another hang over and over again. I looked at it in Instruments and it shows that the main thread is busy during the duration of the hang (2.31 seconds) updating QueryView. From the cause and effect graph, the update is caused by @Observable QueryController .(Bool). Why does it take too long to recalculate the view, given that it's in a LazyVStack? (In other words, why is the hang duration directly proportional to the number of items?) How to fix the performance of this app? I thought adding LazyVStack was all I need to handle the large dataset, but maybe I need to add a custom pagination with .fetchLimit on top of that? (I understand that ModelActor would be an alter
1
0
221
Jan ’26
Accessory View Not Displayed When Switching Input Methods via Bluetooth Keyboard
Hello everyone, When I press Control + Space on my Bluetooth keyboard to trigger input method switching, the accessory view fails to appear. This prevents me from quickly identifying the current input method type. Upon inspecting the View Hierarchy, I noticed that UICursorAccessoryView is not being created. For context, my input method responder inherits from UIResponder and conforms to the UITextInputTraits, UIKeyInput, and UITextInput protocols. The accessory view displays normally during accented input and Chinese input. Could you please guide me on how to troubleshoot this issue?
Replies
4
Boosts
0
Views
534
Activity
Jan ’26
Reply to Bug? SwiftData + inheritance + optional many-to-one relationship
Hello, I am planning a project using SwiftData and inheritance with CloudKit but I am quite concerned about running into this bug. When I click the link to the FB ID above, it comes up empty as do searches for it. Does anyone know the current status?
Replies
Boosts
Views
Activity
Jan ’26
Naming Collision Between Model Attribute and Enum Case in SwiftData and CloudKit
There is a conflict in SwiftData (specifically when synced with CloudKit) when a @Model attribute shares the same name as a case within its assigned enum type. When this occurs, accessing the attribute on a model instance consistently returns the value corresponding to the enum case name, rather than the actual value persisted in the database. Steps to Reproduce Define an enumeration (e.g., Status) with a case that matches a planned property name (e.g., case status). Create a SwiftData @Model that uses this enum. Name the property in the model the same as the enum case. Attempt to save and then retrieve the value. Example Code enum TaskStatus: String, Codable { case status // The conflict source case pending case completed } @Model class TodoItem { // Conflict: Property name matches enum case name var status: TaskStatus init(status: TaskStatus) { self.status = status } } Expected Behavior The property item.status should return the value stored in the database (e.g., .pending or .completed).
Replies
2
Boosts
0
Views
101
Activity
Jan ’26
DNS Proxy system extension – OSSystemExtensionErrorDomain error 9 “validationFailed” on clean macOS machine
Hi, I’m implementing a macOS DNS Proxy as a system extension and running into a persistent activation error: OSSystemExtensionErrorDomain error 9 (validationFailed) with the message: extension category returned error This happens both on an MDM‑managed Mac and on a completely clean Mac (no MDM, fresh install). Setup macOS: 15.x (clean machine, no MDM) Xcode: 16.x Team ID: AAAAAAA111 (test) Host app bundle ID: com.example.agent.NetShieldProxy DNS Proxy system extension bundle ID: com.example.agent.NetShieldProxy.dnsProxy The DNS Proxy is implemented as a NetworkExtension system extension, not an app extension. Host app entitlements From codesign -d --entitlements :- /Applications/NetShieldProxy.app: xml com.apple.application-identifier AAAAAAA111.com.example.agent.NetShieldProxy com.apple.developer.system-extension.install com.apple.developer.team-identifier AAAAAAA111 com.apple.security.app-sandbox com.apple.security.application-groups group.com.example.NetShieldmac com.apple.security.files.user-selected.
Replies
9
Boosts
0
Views
420
Activity
Jan ’26
Reply to evaluatedPolicyDomainState
I’m not sure what sort of help you’re expecting me to provide here. As I mentioned above, this looks like a bug to me. If I had a bug report with a sysdiagnose log, I might — and I want to stress the might here — be able to offer more insight. But without that, I’m flying completely blind. In terms of a workaround, I see two potential options: You could explore user-level workarounds with your user. For example: You might have them reset Face ID (Settings > Face ID & Passcode > Reset Face ID) and re-enroll. Or have them disable the device passcode and then re-enable it. Or have them back up their device and restore from that backup. All of these things are common patterns for clearing out mysterious problems. You could explore code-level workarounds. For example: You might change your system to record multiple biometric domain states. Or have an option to disable biometric domain state checking for specific users. It’s hard to offer specific advice on either of these fronts because I don’t have a relationship
Topic: Privacy & Security SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jan ’26
Reply to Unable to sync SwiftData model fully using CloudKit
The following console log says that your app detected an account switching at the beginning of the launch process, which may erase the existing data created before the switching. It also says that you were using a simulator. CoreData: warning: CoreData+CloudKit: -[PFCloudKitSetupAssistant _checkUserIdentity:]_block_invoke_3(1487): : CKIdentity record has changed from _b09f3f2b1357d21fdd823f58762f6077 to _4e8dc229775b034192825a3081a709a4 error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(1242): : Failed to set up CloudKit integration for store: (URL: file:///Users/yuanping_ke/Library/Developer/CoreSimulator/Devices/BA9191E9-6DB4-4A30-9196-0A6C06A11F2E/data/Containers/Data/Application/5977FE0D-50D4-4AE0-8134-5D8B0B662298/Library/Application%20Support/default.store) Later your app did successfully set up CloudKit integration, as shown below, and then did several successful exports and imports, but it seems that there is no change merged into the store. CoreData: warning:
Replies
Boosts
Views
Activity
Jan ’26
Unable to sync SwiftData model fully using CloudKit
Hey everyone I just ran into an issue where I couldn't sync the model below fully by using CloudKit, enum LinkMapV3_1: VersionedSchema { static let versionIdentifier: Schema.Version = .init(3, 1, 0) static var models: [any PersistentModel.Type] { [AnnotationData.self, GroupData.self, Item.self, Deployment.self, History.self] } // MARK: - Data @Model class AnnotationData { var name: String = var longitude: Double = 0.0 var latitude: Double = 0.0 var order: Int = -1 var level: Int = 1 var detail: String = @Relationship(deleteRule: .nullify, inverse: GroupData.annotation) var groups: [GroupData]? @Relationship(deleteRule: .nullify, inverse: AnnotationData.to) var from: AnnotationData? var to: AnnotationData? var history: History? } // MARK: - History @Model class History { var id: UUID = UUID() var timestamp: Date = Date() @Relationship(deleteRule: .nullify, inverse: AnnotationData.history) var annotations: [AnnotationData]? @Relationship(deleteRule: .nullify, inverse: Group
Replies
1
Boosts
0
Views
300
Activity
Jan ’26
Reply to @ComputedProperty vs copying values SwiftData AppEntity
A @Property variable is computed when the app entity (AppEntity) is initialized, while a @ComputedProperty variable is computed when the entity is returned. So yes, the SwiftData model can become stale if it changes after the app entity is initialized. Assuming that you have a data controller that manages your SwiftData models, I'd think that you can make the SwiftData model associated with the app entity up to date, so that the getters of your @ComputedProperty variables can return the value directly (without doing a fetch). To ensure the SwiftData model is up to date, you might need to observe the notifications triggered by a store change (basically NSManagedObjectContextObjectsDidChange and .NSPersistentStoreRemoteChange, assuming you are using DefaultStore), check if the change is relevant, and re-fetch the data as needed. If you need more discussion on this topic, feel free to follow up with more details about how your SwiftData store may change, Best, —— Ziqi
Replies
Boosts
Views
Activity
Jan ’26
@ComputedProperty vs copying values SwiftData AppEntity
I'm setting up App Entities for my SwiftData models and I'm not sure about the best way to reference SwiftData model properties in the AppEntity. I have a SwiftData model with many properties: @Model final class Contact { @Attribute(.unique) var id: UUID = UUID() var name: String var phoneNumber: String var email: String var website: URL? var birthday: Date? var notes: String // ... many more properties } I want to expose these properties on my AppEntity so they're available for system features, such as giving Apple Intelligence more context about on-screen content. struct ContactEntity: AppEntity { var id: UUID @Property(title: Name) var name: String @Property(title: Phone) var phoneNumber: String @Property(title: Email) var email: String // ... all the other properties } I couldn't find guidance in the documentation for this specific situation. I've considered two approaches: Add @Property variables to the AppEntity for each SwiftData model property and copy all values fr
Replies
1
Boosts
0
Views
149
Activity
Jan ’26
Reply to Deleting Production Database SwiftData
Just to add that a code snippet showing how to add multiple SwiftData model configurations to a model container is shown here. Also, this technote talks about how to work with default data. It covers Core Data and hasn't been updated, but the main idea, which I believe is worth mentioning, applies to SwiftData apps as well. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Jan ’26
Deleting Production Database SwiftData
Hi all, I have setup my app to use SwiftData with CloudKit sync. I have a production environment and development environment. I can reset the development environment for myself and all users in CloudKit console, but I can't reset the production one as it's tried to users' iCloud accounts, so I've added a button in-app for that feature. In the onboarding of my app, I pre-seed the DB with some default objects, which should be persisted between app install. The issue I'm running into is that I'm unable to force-pull these models from iCloud during the onboarding of a clean re-install, which leads to the models later appearing as duplicates once the user has been on the app for a few minutes and it has pulled from their iCloud account. If anyone has any suggestions on how to handle this issue, I would greatly appreciate it.
Replies
2
Boosts
0
Views
273
Activity
Jan ’26
Handling Context Save Errors
I was wondering if errors are common for the code below for saving SwiftData data and what would be the best way to handle them (popup, closing the app)? do { try modelContext.save() } catch { print(error) }
Topic: Design SubTopic: General Tags:
Replies
1
Boosts
0
Views
286
Activity
Jan ’26
SwiftData & CloudKit: Arrays of Codable Structs Causing NSKeyedUnarchiveFromData Error
I have SwiftData models containing arrays of Codable structs that worked fine before adding CloudKit capability. I believe they are the reason I started seeing errors after enabling CloudKit. Example model: @Model final class ProtocolMedication { var times: [SchedulingTime] = [] // SchedulingTime is Codable // other properties... } After enabling CloudKit, I get this error logged to the console: 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release CloudKit Console shows this times data as plain text instead of bplist format. Other struct/enum properties display correctly (I think) as bplist in CloudKit Console. The local SwiftData storage handled these arrays fine - this issue only appeared with CloudKit integration. What's the recommended approach for storing arrays of Codable structs in SwiftData models that sync with CloudKit?
Replies
8
Boosts
0
Views
933
Activity
Jan ’26
Reply to SwiftUI TextEditor: replaced text jumps outside current selection
Hi Albert, thank you for replying. Here is my Richnote class: import SwiftUI import SwiftData @Model final class Richnote { @Attribute(.externalStorage) var content : AttributedString var createdAt: Date = Date() init(content: AttributedString) { self.content = content } }
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jan ’26
Performance in Large Datasets (SwiftUI+SwiftData app)
Hi everyone, In the simple app below, I have a QueryView that has LazyVStack containing 100k TextField's that edit the item's content. The items are fetched with a @Query. On launch, the app will generate 100k items. Once created, when I press any of the TextField's , a severe hang happens, and every time I type a single character, it will cause another hang over and over again. I looked at it in Instruments and it shows that the main thread is busy during the duration of the hang (2.31 seconds) updating QueryView. From the cause and effect graph, the update is caused by @Observable QueryController .(Bool). Why does it take too long to recalculate the view, given that it's in a LazyVStack? (In other words, why is the hang duration directly proportional to the number of items?) How to fix the performance of this app? I thought adding LazyVStack was all I need to handle the large dataset, but maybe I need to add a custom pagination with .fetchLimit on top of that? (I understand that ModelActor would be an alter
Replies
1
Boosts
0
Views
221
Activity
Jan ’26