Search results for

“SwiftData inheritance relationship”

4,981 results found

Post

Replies

Boosts

Views

Activity

Reply to SwiftData with CloudKit in Widgets
An app and its extensions can share a SwiftData store located in a shared App Group container. The following Apple sample demonstrates that: Adopting SwiftData for a Core Data app The discussion in this post may help as well, if you have any data update issue. CloudKit integration adds more complexity on this topic. You can start with checking if this post helps. SwiftData + CloudKit uses NSPersistentCloudKitContainer under the hood, and so the content applies. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Sep ’25
Reply to SwiftData & CloudKit: Arrays of Codable Structs Causing NSKeyedUnarchiveFromData Error
Did you wait some time to make sure the error didn't pop up? It might take a minute or two. Try inserting a record then re-running and waiting a few minutes. Yeah, I've tried waiting until seeing the new record being synchronized across my devices, and haven't seen the issue. NSKeyedUnarchiveFromData is the default transformer and comes to play when you use a Core Data / SwiftData transformable attribute without explicitly specifying a transformer. Unless you are using a transformable attribute, it shouldn't be engaged. My best guess is that your CloudKit schema / data contains something that needs a transformer (due to your historical changes?), and that triggers the error when NSPersistentCloudKitContainer tries to synchronize the data from the server to your device. If that is the case, consider cleaning up the schema and data on the CloudKit server. Assuming you are on the CloudKit development environment, you can remove the existing schema and data by resetting the environment, and then re-creat
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’25
Reply to Network Extension App for MacOS with 3 Extensions
Thanks a lot for your detailed explanation of the relevant concepts @DTS Engineer. It's very helpful and I really appreciate your time and support here. I am using Content Filter Extension to capture/log some basic details. As you've mentioned, it's the simplest one. I wanted to have a working network extension app for MacOS to begin with. However, my intention is to capture real network traffic with HTTP/HTTPS logs, actual urls, and actual endpoints along with DNS Record details by using all the relevant extensions together. Right now, My app is working with Content Filter extension. As you suggested, I am building with two Xcode targets, one with Main app and other with the System Extension(which contains multiple network extensions). To start with, I am only focusing on HTTP logs capture using NETransparentProxyProvider for now(Capturing/logging HTTPS requires more work dealing with TLS and Certificates, will look into this later). I am able to build, and run this binary with these added new files for AppP
Sep ’25
Reply to v1/appPriceSchedules 409
Also started seeing this around 2025-09-05. Using the manualPrice id returned from a previous relationships/manualPrices result. Error: Request https://api.appstoreconnect.apple.com/v1/inAppPurchasePriceSchedules failed with status code 409. Related response error(s): The request failed with response code 409 ENTITY_ERROR.INCLUDED.INVALID_ID The provided entity id is invalid. The provided included entity id 'eyJzIjoiNjQ1MTIxNzg3OSIsInQiOiJVU0EiLCJwIjoiMTAwOTQiLCJzZCI6MC4wLCJlZCI6MC4wfQ' has invalid format).
Sep ’25
SwiftData with CloudKit in Widgets
Good morning everyone! Today I have a question about using SwiftData with CloudKit and Widgets. I recently set up my project for SwiftData and CloudKit synchronization, but for some reason, I’m not able to give my Widget access to this data. CloudKit works perfectly fine for my main app, but the Widget only shows placeholder data(the placeholder data which were defined in the get functions as catch, this is sure). I have set the CloudKit capability for my Widget extension and tried fetching data with the get-functions in the code below. I also ensured that the data model files are members of the Widget extension target and that the Widget extension uses the same CloudKit container as the main app. I wondered if it is possible and reasonable to save a copy of my CloudKit data in an App Group container, but in that case, the information shown in the Widget are not always up-to-date, so a solution that fetches data directly from CloudKit would be better. Has anyone had experience with this case
1
0
227
Sep ’25
Interactive Widget with SwiftData Not Triggering iCloud Sync
Hello everyone, I'm developing an app for iOS 18 using SwiftData, with iCloud synchronization enabled. My app also includes an interactive widget that allows users to mark tasks as complete, similar to Apple's Reminders widget. I'm facing a specific issue with how iCloud sync is triggered when changes are made from the widget. My Setup: Xcode 16 Swift 6 / iOS 18 SwiftData with iCloud Sync enabled. An interactive widget using App Intents to modify the SwiftData model. What's working correctly: App to Widget (Same Device): If I mark a task as complete in the main app, the widget on the same device updates instantly. Widget to App (Same Device): If I mark a task as complete using the interactive widget, the main app on the same device reflects this change immediately. App to App (Across Devices): If I make a change in the app on my iPhone, it syncs correctly via iCloud and appears in the app on my iPad. The Problem: The synchronization issue occurs specifically when an action is initia
1
0
158
Sep ’25
Modelactors, Repository and bootloader
In iOS 26, should we have bootloader that runs the repo on startup - or should we have that inside tasks in root view? we have repos that runs as a «closed» functions, we dont throw but updates swiftdata and we use @query in the views. So what is best? and for the repo we should have a repo that runs the upserts manage relations eg? Should that run on a modelactor?
0
0
222
Sep ’25
Using SwiftData with a local and CloudKit backed configuration at the same time
I'm trying to set up an application using SwiftData to have a number of models backed by a local datastore that's not synced to CloudKit, and another set of models that is. I was able to achieve this previously with Core Data using multiple NSPersistentStoreDescription instances. The set up code looks something like: do { let fullSchema = Schema([ UnsyncedModel.self, SyncedModel.self, ]) let localSchema = Schema([UnsyncedModel.self]) let localConfig = ModelConfiguration(schema: localSchema, cloudKitDatabase: .none) let remoteSchema = Schema([SyncedModel.self]) let remoteConfig = ModelConfiguration(schema: remoteSchema, cloudKitDatabase: .automatic) container = try ModelContainer(for: fullSchema, configurations: localConfig, remoteConfig) } catch { fatalError(Failed to configure SwiftData container.) } However, it doesn't seem to work as expected. If I remove the synced/remote schema and configuration then everything works fine, but the moment I add in the remote schema and configuration I ge
3
0
420
Sep ’25
Reply to Drag-and-Drop from macOS Safari to NSItemProvider fails due to URL not being a file:// URL
(Re: previous answers - skip if you haven't followed the saga) Adding some context for the answer. I added AppKit specifically because it's not UIKit, as I didn't want an answer for iOS or ipadOS, but macOS. The only SwiftUI line is the onDrag, that I faithfully added to the line as the caller, but I didn't think I'd have a different DropHandler for macOS and ipadOS, the culprit seemingly being the onDrag SwiftUI part that tries to give me only the good thing on macOS, but somehow is unusable. As I repeated, I wanted to quickly iterate and used the hacks instead of trying to use the Async versions, where some versions aren't actually available. The final code will be in Async, thank you. My first SwiftUI app was with GCD because there wasn't an alternative back then. There's one now. But I'm also butting heads with SwiftData, where models cannot be Sendable, but Async are also required to be sendable, so I've had a lot of fun on this topic. With the nearly 200 trials I had to do in order to make it w
Topic: UI Frameworks SubTopic: AppKit Tags:
Sep ’25
SwiftData and CloudKit: NSKeyedUnarchiveFromData Error
I just made a small test app that uses SwiftData with CloudKit capability. I created a simple Book model as seen below. It looks like enums and structs when used with CloudKit capability all trigger this error: 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release I fixed the error by using genreRaw String and using a computed property to use it in the app, but it popped back up after adding the ReadingProgress struct Should I ignore the error and assume Apple still supports enums and codable structs when using SwiftData with CloudKit? import SwiftData @Model class Book { var title: String = var author: String = var genreRaw: String = Genre.fantasy.rawValue var review: String = var rating: Int = 3 var progress: ReadingProgress? var genre: Genre { get { Genre(rawValue: genreRaw) ?? Genre.fantasy } set { genreRaw = newValue.rawValue } } init(title: String, author: String, genre: Genre, review: String, rating: Int, progress: Readin
1
0
368
Sep ’25
Helper app is sandboxed (entitlement + runtime check), but `URLsForDirectory:` returns user home (`/Users//`) instead of container path — why?
Problem summary I have a macOS helper app that is launched from a sandboxed main app. The helper: has com.apple.security.app-sandbox = true and com.apple.security.inherit = true in its entitlements, is signed and embedded inside the main app bundle (placed next to the main executable in Contents/MacOS), reports entitlement_check = 1 (code signature contains sandbox entitlement, implemented via SecStaticCode… check), sandbox_check(getpid(), NULL, 0) returns 1 (runtime sandbox enforcement present), APP_SANDBOX_CONTAINER_ID environment variable is not present (0). Despite that, Cocoa APIs return non-container home paths: NSHomeDirectory() returns /Users/<me>/ (the real home). [[NSFileManager defaultManager] URLsForDirectory:inDomains:] and URLForDirectory:inDomain:appropriateForURL:create:error: return paths rooted at /Users/<me>/ (not under ~/Library/Containers/<app_id>/Data/...) — i.e. they look like non-sandboxed locations. However, one important exception: URLForDirectory:... for NSItemRepl
7
0
230
Sep ’25
Reply to SwiftData & CloudKit: Arrays of Codable Structs Causing NSKeyedUnarchiveFromData Error
I switch to using Data with Transient computed property and it still is showing the same error logged to the console: import SwiftData @Model final class ProtocolMedication { var uuid: UUID = UUID() var createdAt: Date = Date() var frequency: SchedulingFrequency = SchedulingFrequency.atRegularIntervals var interval: SchedulingInterval = SchedulingInterval(days: 1) var startDate: Date = Date() var timesData: Data? var dayOfWeekSelection: DayOfWeekSelection = DayOfWeekSelection(days: [1]) var injectionRotationConfig: InjectionRotationConfig = InjectionRotationConfig() var medicationConcentration: MedicationConcentration = MedicationConcentration(value: nil, unit: nil) var medication: Medication? @Relationship(deleteRule: .cascade, inverse: ScheduledDose.protocolMed) var _scheduledDoses: [ScheduledDose]? @Relationship(deleteRule: .cascade, inverse: DoseLog.protocolMed) var _doseLogs: [DoseLog]? @Transient var times: [SchedulingTime] { get { guard let data = timesData else { return [] }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’25
Reply to SwiftData & CloudKit: Arrays of Codable Structs Causing NSKeyedUnarchiveFromData Error
Do you have a feedback report yet? If not, I’d suggest that you file one and share your report ID here. For a workaround, you might consider making SchedulingTime a SwiftData model, if that is appropriate, and relating it to ProtocolMedication with a too-many relationship. You can also consider using Data directly for persistence, and providing a transient (@Transient) property for the access to the struct array (only) in memory. A transient property can't be used in a query though. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’25
SwiftData Fatal error
I'm developing an app that uses CloudKit synchronization with SwiftData and on visionOS I added an App Settings bundle. I have noticed that sometimes, when the app is open and the user changes a setting from the App Settings bundle, the following fatal error occurs: SwiftData/BackingData.swift:831: Fatal error: This model instance was destroyed by calling ModelContext.reset and is no longer usable. The setting is read within the App struct in the visionOS app target using @AppStorage and this value is in turn used to set the passthrough video dimming via the .preferredSurroundingsEffect modifier. The setting allows the user to specify the dimming level as dark, semi dark, or ultra dark. The fatal error appears to occur intermittently although the first time it was observed was after adding the settings bundle. As such, I suspect there is some connection between those code changes and this fatal error even though they do not directly relate to SwiftData.
1
0
287
Sep ’25
Reply to SwiftData with CloudKit in Widgets
An app and its extensions can share a SwiftData store located in a shared App Group container. The following Apple sample demonstrates that: Adopting SwiftData for a Core Data app The discussion in this post may help as well, if you have any data update issue. CloudKit integration adds more complexity on this topic. You can start with checking if this post helps. SwiftData + CloudKit uses NSPersistentCloudKitContainer under the hood, and so the content applies. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Sep ’25
Reply to Interactive Widget with SwiftData Not Triggering iCloud Sync
You might want to check if this post answers your question. SwiftData + CloudKit uses NSPersistentCloudKitContainer under the hood, and so the content applies. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Sep ’25
Reply to SwiftData & CloudKit: Arrays of Codable Structs Causing NSKeyedUnarchiveFromData Error
Did you wait some time to make sure the error didn't pop up? It might take a minute or two. Try inserting a record then re-running and waiting a few minutes. Yeah, I've tried waiting until seeing the new record being synchronized across my devices, and haven't seen the issue. NSKeyedUnarchiveFromData is the default transformer and comes to play when you use a Core Data / SwiftData transformable attribute without explicitly specifying a transformer. Unless you are using a transformable attribute, it shouldn't be engaged. My best guess is that your CloudKit schema / data contains something that needs a transformer (due to your historical changes?), and that triggers the error when NSPersistentCloudKitContainer tries to synchronize the data from the server to your device. If that is the case, consider cleaning up the schema and data on the CloudKit server. Assuming you are on the CloudKit development environment, you can remove the existing schema and data by resetting the environment, and then re-creat
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’25
Reply to Network Extension App for MacOS with 3 Extensions
Thanks a lot for your detailed explanation of the relevant concepts @DTS Engineer. It's very helpful and I really appreciate your time and support here. I am using Content Filter Extension to capture/log some basic details. As you've mentioned, it's the simplest one. I wanted to have a working network extension app for MacOS to begin with. However, my intention is to capture real network traffic with HTTP/HTTPS logs, actual urls, and actual endpoints along with DNS Record details by using all the relevant extensions together. Right now, My app is working with Content Filter extension. As you suggested, I am building with two Xcode targets, one with Main app and other with the System Extension(which contains multiple network extensions). To start with, I am only focusing on HTTP logs capture using NETransparentProxyProvider for now(Capturing/logging HTTPS requires more work dealing with TLS and Certificates, will look into this later). I am able to build, and run this binary with these added new files for AppP
Replies
Boosts
Views
Activity
Sep ’25
Reply to v1/appPriceSchedules 409
Also started seeing this around 2025-09-05. Using the manualPrice id returned from a previous relationships/manualPrices result. Error: Request https://api.appstoreconnect.apple.com/v1/inAppPurchasePriceSchedules failed with status code 409. Related response error(s): The request failed with response code 409 ENTITY_ERROR.INCLUDED.INVALID_ID The provided entity id is invalid. The provided included entity id 'eyJzIjoiNjQ1MTIxNzg3OSIsInQiOiJVU0EiLCJwIjoiMTAwOTQiLCJzZCI6MC4wLCJlZCI6MC4wfQ' has invalid format).
Replies
Boosts
Views
Activity
Sep ’25
SwiftData with CloudKit in Widgets
Good morning everyone! Today I have a question about using SwiftData with CloudKit and Widgets. I recently set up my project for SwiftData and CloudKit synchronization, but for some reason, I’m not able to give my Widget access to this data. CloudKit works perfectly fine for my main app, but the Widget only shows placeholder data(the placeholder data which were defined in the get functions as catch, this is sure). I have set the CloudKit capability for my Widget extension and tried fetching data with the get-functions in the code below. I also ensured that the data model files are members of the Widget extension target and that the Widget extension uses the same CloudKit container as the main app. I wondered if it is possible and reasonable to save a copy of my CloudKit data in an App Group container, but in that case, the information shown in the Widget are not always up-to-date, so a solution that fetches data directly from CloudKit would be better. Has anyone had experience with this case
Replies
1
Boosts
0
Views
227
Activity
Sep ’25
Interactive Widget with SwiftData Not Triggering iCloud Sync
Hello everyone, I'm developing an app for iOS 18 using SwiftData, with iCloud synchronization enabled. My app also includes an interactive widget that allows users to mark tasks as complete, similar to Apple's Reminders widget. I'm facing a specific issue with how iCloud sync is triggered when changes are made from the widget. My Setup: Xcode 16 Swift 6 / iOS 18 SwiftData with iCloud Sync enabled. An interactive widget using App Intents to modify the SwiftData model. What's working correctly: App to Widget (Same Device): If I mark a task as complete in the main app, the widget on the same device updates instantly. Widget to App (Same Device): If I mark a task as complete using the interactive widget, the main app on the same device reflects this change immediately. App to App (Across Devices): If I make a change in the app on my iPhone, it syncs correctly via iCloud and appears in the app on my iPad. The Problem: The synchronization issue occurs specifically when an action is initia
Replies
1
Boosts
0
Views
158
Activity
Sep ’25
Modelactors, Repository and bootloader
In iOS 26, should we have bootloader that runs the repo on startup - or should we have that inside tasks in root view? we have repos that runs as a «closed» functions, we dont throw but updates swiftdata and we use @query in the views. So what is best? and for the repo we should have a repo that runs the upserts manage relations eg? Should that run on a modelactor?
Replies
0
Boosts
0
Views
222
Activity
Sep ’25
Using SwiftData with a local and CloudKit backed configuration at the same time
I'm trying to set up an application using SwiftData to have a number of models backed by a local datastore that's not synced to CloudKit, and another set of models that is. I was able to achieve this previously with Core Data using multiple NSPersistentStoreDescription instances. The set up code looks something like: do { let fullSchema = Schema([ UnsyncedModel.self, SyncedModel.self, ]) let localSchema = Schema([UnsyncedModel.self]) let localConfig = ModelConfiguration(schema: localSchema, cloudKitDatabase: .none) let remoteSchema = Schema([SyncedModel.self]) let remoteConfig = ModelConfiguration(schema: remoteSchema, cloudKitDatabase: .automatic) container = try ModelContainer(for: fullSchema, configurations: localConfig, remoteConfig) } catch { fatalError(Failed to configure SwiftData container.) } However, it doesn't seem to work as expected. If I remove the synced/remote schema and configuration then everything works fine, but the moment I add in the remote schema and configuration I ge
Replies
3
Boosts
0
Views
420
Activity
Sep ’25
Reply to Drag-and-Drop from macOS Safari to NSItemProvider fails due to URL not being a file:// URL
(Re: previous answers - skip if you haven't followed the saga) Adding some context for the answer. I added AppKit specifically because it's not UIKit, as I didn't want an answer for iOS or ipadOS, but macOS. The only SwiftUI line is the onDrag, that I faithfully added to the line as the caller, but I didn't think I'd have a different DropHandler for macOS and ipadOS, the culprit seemingly being the onDrag SwiftUI part that tries to give me only the good thing on macOS, but somehow is unusable. As I repeated, I wanted to quickly iterate and used the hacks instead of trying to use the Async versions, where some versions aren't actually available. The final code will be in Async, thank you. My first SwiftUI app was with GCD because there wasn't an alternative back then. There's one now. But I'm also butting heads with SwiftData, where models cannot be Sendable, but Async are also required to be sendable, so I've had a lot of fun on this topic. With the nearly 200 trials I had to do in order to make it w
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Sep ’25
SwiftData and CloudKit: NSKeyedUnarchiveFromData Error
I just made a small test app that uses SwiftData with CloudKit capability. I created a simple Book model as seen below. It looks like enums and structs when used with CloudKit capability all trigger this error: 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release I fixed the error by using genreRaw String and using a computed property to use it in the app, but it popped back up after adding the ReadingProgress struct Should I ignore the error and assume Apple still supports enums and codable structs when using SwiftData with CloudKit? import SwiftData @Model class Book { var title: String = var author: String = var genreRaw: String = Genre.fantasy.rawValue var review: String = var rating: Int = 3 var progress: ReadingProgress? var genre: Genre { get { Genre(rawValue: genreRaw) ?? Genre.fantasy } set { genreRaw = newValue.rawValue } } init(title: String, author: String, genre: Genre, review: String, rating: Int, progress: Readin
Replies
1
Boosts
0
Views
368
Activity
Sep ’25
Helper app is sandboxed (entitlement + runtime check), but `URLsForDirectory:` returns user home (`/Users//`) instead of container path — why?
Problem summary I have a macOS helper app that is launched from a sandboxed main app. The helper: has com.apple.security.app-sandbox = true and com.apple.security.inherit = true in its entitlements, is signed and embedded inside the main app bundle (placed next to the main executable in Contents/MacOS), reports entitlement_check = 1 (code signature contains sandbox entitlement, implemented via SecStaticCode… check), sandbox_check(getpid(), NULL, 0) returns 1 (runtime sandbox enforcement present), APP_SANDBOX_CONTAINER_ID environment variable is not present (0). Despite that, Cocoa APIs return non-container home paths: NSHomeDirectory() returns /Users/<me>/ (the real home). [[NSFileManager defaultManager] URLsForDirectory:inDomains:] and URLForDirectory:inDomain:appropriateForURL:create:error: return paths rooted at /Users/<me>/ (not under ~/Library/Containers/<app_id>/Data/...) — i.e. they look like non-sandboxed locations. However, one important exception: URLForDirectory:... for NSItemRepl
Replies
7
Boosts
0
Views
230
Activity
Sep ’25
Reply to SwiftData & CloudKit: Arrays of Codable Structs Causing NSKeyedUnarchiveFromData Error
I switch to using Data with Transient computed property and it still is showing the same error logged to the console: import SwiftData @Model final class ProtocolMedication { var uuid: UUID = UUID() var createdAt: Date = Date() var frequency: SchedulingFrequency = SchedulingFrequency.atRegularIntervals var interval: SchedulingInterval = SchedulingInterval(days: 1) var startDate: Date = Date() var timesData: Data? var dayOfWeekSelection: DayOfWeekSelection = DayOfWeekSelection(days: [1]) var injectionRotationConfig: InjectionRotationConfig = InjectionRotationConfig() var medicationConcentration: MedicationConcentration = MedicationConcentration(value: nil, unit: nil) var medication: Medication? @Relationship(deleteRule: .cascade, inverse: ScheduledDose.protocolMed) var _scheduledDoses: [ScheduledDose]? @Relationship(deleteRule: .cascade, inverse: DoseLog.protocolMed) var _doseLogs: [DoseLog]? @Transient var times: [SchedulingTime] { get { guard let data = timesData else { return [] }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’25
Reply to SwiftData & CloudKit: Arrays of Codable Structs Causing NSKeyedUnarchiveFromData Error
Do you have a feedback report yet? If not, I’d suggest that you file one and share your report ID here. For a workaround, you might consider making SchedulingTime a SwiftData model, if that is appropriate, and relating it to ProtocolMedication with a too-many relationship. You can also consider using Data directly for persistence, and providing a transient (@Transient) property for the access to the struct array (only) in memory. A transient property can't be used in a query though. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’25
SwiftData Fatal error
I'm developing an app that uses CloudKit synchronization with SwiftData and on visionOS I added an App Settings bundle. I have noticed that sometimes, when the app is open and the user changes a setting from the App Settings bundle, the following fatal error occurs: SwiftData/BackingData.swift:831: Fatal error: This model instance was destroyed by calling ModelContext.reset and is no longer usable. The setting is read within the App struct in the visionOS app target using @AppStorage and this value is in turn used to set the passthrough video dimming via the .preferredSurroundingsEffect modifier. The setting allows the user to specify the dimming level as dark, semi dark, or ultra dark. The fatal error appears to occur intermittently although the first time it was observed was after adding the settings bundle. As such, I suspect there is some connection between those code changes and this fatal error even though they do not directly relate to SwiftData.
Replies
1
Boosts
0
Views
287
Activity
Sep ’25