Search results for

“SwiftData inheritance relationship”

4,981 results found

Post

Replies

Boosts

Views

Activity

CloudKit and SwiftData not syncing on MacOS
I have a simple app that uses SwiftUI and SwiftData to maintain a database. The app runs on multiple iPhones and iPads and correctly synchronises across those platforms. So I am correct setting Background Modes and Remote Notifications. I have also correctly setup my Model Configuration and ModelContainer (Otherwise I would expect syncing to fail completely). The problem arises when I run on a Mac (M1 or M3) either using Mac Designed for iPad or Mac Catalyst. This can be debugging in Xcode or running the built app. Then the app does not reflect changes made in the iPhone or iPad apps unless I follow a specific sequence. Leave the app, (e.g click on a Finder window), then come back to the app (i.e click on the app again). Now the app will show the changes made on the iPhone/iPad. It looks like the app on the Mac is not processing remote notifications when in the background - it only performs them when the app has just become active. It also looks like the Mac is not performing these sync operations wh
3
0
847
Sep ’25
View with FetchRequest doesnt update on change
Hello guys, this is my first post to this forum and really hope that somebody can help me here. I would highly appreciate every help! I am writing my first app with Swift UI (never used UIKit before) which I want to publish later on. This is also my first app which has CoreData implemented. For example I use the following entities: Family, Person 1 Persons can have 1 Family 1 Family can have many Persons My App is structured as the following: ContentView: Contains a TabView with 2 other views in it. A Settings View and a View with a LazyVGrid. LazyVGrid View: This View shows a GridItem for every Family. I get the Families with the following Fetchrequest: @Environment(.managedObjectContext) private var viewContext // These are the Families from the FetchRequest @FetchRequest(entity: Family.entity(), sortDescriptors: [NSSortDescriptor(keyPath: Family.created, ascending: false)] ) var families: FetchedResults Every GridItem is linking to a FamilyDetailView via NavigationLink. So i pass the family as the followin
1
0
794
Sep ’25
SwiftData ModelCoders.swift:1069 Unable to decode
Hello Developer Support, I have the following code and the following crash. How can the swift data model unable to decode and yet able to display the decoded value at the same time?! What's missing here? CODE: @Model final class DisplayCache { init(point: MKMapPoint) { self.point = point } var point: MKMapPoint } CRASH SwiftData/ModelCoders.swift:1069: Fatal error: Unable to decode this value MKMapPoint(x: 74358466.66307731, y: 97927933.41833577)
3
0
172
Sep ’25
CloudKit Sync with TestFlight
I'm working on a new app with SwiftData and now adding CloudKit Sync. Everything is working fine in the simulator against the development CloudKit Schema. I successfully deployed the schema to production. However, the TestFlight builds fail against production. This is what I see in the logs, but I haven't been able to find info on how to fix it. Help appreciated. CoreData+CloudKit: -[NSCloudKitMirroringDelegate _requestAbortedNotInitialized:](2205): - Never successfully initialized and cannot execute request '' due to error: Error Domain=CKErrorDomain Code=2 CKInternalErrorDomain: 1011 UserInfo={ContainerID=, NSDebugDescription=CKInternalErrorDomain: 1011, CKPartialErrors=, RequestUUID=, NSLocalizedDescription=, CKErrorDescription=, NSUnderlyingError=0x1078e9fe0 {Error Domain=CKInternalErrorDomain Code=1011 UserInfo={CKErrorDescription=, NSLocalizedDescription=, CKPartialErrors=}}} CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(1153): : Successfully set up Cloud
1
0
132
Sep ’25
Reply to iOS 26 SwiftData crash does not happen in iOS 16
The error message seems to indicate a type mis-match, likely the data in your JSON data being a number, while the corresponding SwiftData attribute being a string. That mismatch triggers an error when your app saves the SwiftData store. If you save your SwiftData store immediately after modelContext.insert(decodedResponse), as shown below, you will see the error: func getBestSellerLists() async { ... modelContext.insert(decodedResponse) // Add the following code to save the context and trigger the error. do { try modelContext.save() // This triggers the error. } catch { print(error) } ... } You can probably use the following flow to figure out which piece of data triggers the type mismatch: Add the code snippet above to your project so you can trigger the crash in a controlled way. Replace the JSON data from the remote server with a local JSON file so you can easily change data. Remove part of the data from the JSON file, change your SwiftData models to match the schema, an
Sep ’25
Reply to How to configure macOS app permission MANUALLY (not GUI)
The modeling tool is called MagicDraw, a UML modeling tool written in Java and originally created by a company No Magic, which was acquired by Dassault Systèmes. I have a long relationship with this company, so I have some insight into the tool, and some source code to support my customization work for special modeling strategies, however I have not enough sources to rebuild the tool on my own. The reason for the many copies is to keep one clean copy and then some copy s in various states of customization. After upgrading to Sequoia from Mojave, I started the clean copy of MagicDraw first, in the hope it would attach all security attributes to it. But unfortunately Sequoia picked one of the customized copies as the one and only entry in Privacy & Security -> Local Network. Since there is no GUI provision in Local Networks to add or remove applications, it requires some hacking (starting and killing of the app, combined with enabling and removing in Local Network) to provide the clean MagicDraw
Sep ’25
Mutating an array of model objects that is a child of a model object
Hi all, In my SwiftUI / SwiftData / Cloudkit app which is a series of lists, I have a model object called Project which contains an array of model objects called subprojects: final class Project1 { var name: String = @Relationship(deleteRule: .cascade, inverse: Subproject.project) var subprojects : [Subproject]? init(name: String) { self.name = name self.subprojects = [] } } The user will select a project from a list, which will generate a list of subprojects in another list, and if they select a subproject, it will generate a list categories and if the user selects a category it will generate another list of child objects owned by category and on and on. This is the pattern in my app, I'm constantly passing arrays of model objects that are the children of other model objects throughout the program, and I need the user to be able to add and remove things from them. My initial approach was to pass these arrays as bindings so that I'd be able to mutate them. This worked for the most part but
5
0
237
Sep ’25
Reply to Allow "Browser" to find devices on local networks
I’d like to clarify your overall goal here. Are you planning to ship an app based on Chromium? Or are you building some sort of plug-in that you install within Chromium? This matters because… [quote='800879021, poluyanov, /thread/800879, /profile/poluyanov'] simply overwriting files in the app bundle [/quote] Right. That breaks the seal on the code signature, which causes problems for all privacy subsystems, which rely on the code signature to track the identity of your code, that is, to determine that version N+1 of your app is the ‘same code’ as version N. This is something we call out in TN3179 Understanding local network privacy: To ensure that local network privacy reliably tracks the identity of your macOS program, sign it with an Apple-issued code-signing identity. Most apps don’t suffer from this problem because, when Xcode rebuilds the app, it signs result. If you’ve selected an Apple-issued code-signing identity, the new app has the same designated requirement as the previous app, and thus the OS tr
Sep ’25
Inheritance in SwiftData — Fatal error: Never access a full future backing data
I'm implementing SwiftData with inheritance in an app. I have an Entity class with a property name. This class is inherited by two other classes: Store and Person. The Entity model has a one-to-many relationship with a Transaction class. I can list all my Entity models in a List with a @Query annotation without a problem. However, then I try to access the name property of an Entity from a Transaction relationship, the app crashes with the following error: Thread 1: Fatal error: Never access a full future backing data - PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(backing: SwiftData.PersistentIdentifier.PersistentIdentifierBacking.managedObjectID(0x96530ce28d41eb63 ))) with Optional(F07E7E23-F8F0-4CC0-B282-270B5EDDC7F3) From my attempts to fix the issue, I noticed that: The crash seems related to the relationships with classes that has inherit from another class, since it only happens there. When I create new data, I can usually acces
1
0
272
Sep ’25
Save SwiftData object for model with one to many relationship
First the Model: import Foundation import SwiftData //Model for Earned Value Analysis @Model final class CostReport{ var aCWP: Double //Actual Cost of Work Performed var bCWP: Double //Budgeted Cost of Work Performed var bCWS: Double // Budgeted Cost of Work Scheduled var cumACWP: Double// Cumlative Actual Cost of Work Performed var cumBCWP: Double // Cumlative Budgeted Cost of Work Performed var cumBCWS: Double // Cumlative Budgeted Cost of Work Scheduled var startDateOfPeriod: Date var endDateOfPeriod: Date var contract: Contract? init(aCWP: Double = 0.0, bCWP: Double = 0.0, bCWS: Double = 0.0, cumACWP: Double = 0.0, cumBCWP: Double = 0.0, cumBCWS: Double = 0.0, startDateOfPeriod: Date = .now, endDateOfPeriod: Date = .now, contract: Contract) { self.aCWP = aCWP self.bCWP = bCWP self.bCWS = bCWS self.cumACWP = cumACWP self.cumBCWP = cumBCWP self.cumBCWS = cumBCWS self.startDateOfPeriod = startDateOfPeriod self.endDateOfPeriod = endDateOfPeriod self.contract = contract } } @Model //Model for Contract
4
0
246
Sep ’25
Reply to Save SwiftData object for model with one to many relationship
import SwiftData //Model for Earned Value Analysis The Model @Model final class CostReport{ var aCWP: Double //Actual Cost of Work Performed var bCWP: Double //Budgeted Cost of Work Performed var bCWS: Double // Budgeted Cost of Work Scheduled var cumACWP: Double// Cumlative Actual Cost of Work Performed var cumBCWP: Double // Cumlative Budgeted Cost of Work Performed var cumBCWS: Double // Cumlative Budgeted Cost of Work Scheduled var startDateOfPeriod: Date var endDateOfPeriod: Date var contract: Contract? init(aCWP: Double = 0.0, bCWP: Double = 0.0, bCWS: Double = 0.0, cumACWP: Double = 0.0, cumBCWP: Double = 0.0, cumBCWS: Double = 0.0, startDateOfPeriod: Date = .now, endDateOfPeriod: Date = .now, contract: Contract) { self.aCWP = aCWP self.bCWP = bCWP self.bCWS = bCWS self.cumACWP = cumACWP self.cumBCWP = cumBCWP self.cumBCWS = cumBCWS self.startDateOfPeriod = startDateOfPeriod self.endDateOfPeriod = endDateOfPeriod self.contract = contract } } @Model //Model for Contracts final class Contract{ v
Sep ’25
Reply to SMAppService Sample Code seems broken
I have noticed that launchd is changing my status to 78 at times which I vaguely remember is a permissions issue but I can't find the relevant documentation anymore. I'm not actually attempting to do anything even remotely privileged in the code yet; the example service is unchanged save for a liberal blanketing of print() calls to try and see if anything is ever running. Nothing ever shows up on the console so I have no clue what would lack permission to run if I'm getting SMAppService.Status.enabled back from the service object. Does the nested launchd job not inherit the parent app's entitlements or something?
Sep ’25
CloudKit and SwiftData not syncing on MacOS
I have a simple app that uses SwiftUI and SwiftData to maintain a database. The app runs on multiple iPhones and iPads and correctly synchronises across those platforms. So I am correct setting Background Modes and Remote Notifications. I have also correctly setup my Model Configuration and ModelContainer (Otherwise I would expect syncing to fail completely). The problem arises when I run on a Mac (M1 or M3) either using Mac Designed for iPad or Mac Catalyst. This can be debugging in Xcode or running the built app. Then the app does not reflect changes made in the iPhone or iPad apps unless I follow a specific sequence. Leave the app, (e.g click on a Finder window), then come back to the app (i.e click on the app again). Now the app will show the changes made on the iPhone/iPad. It looks like the app on the Mac is not processing remote notifications when in the background - it only performs them when the app has just become active. It also looks like the Mac is not performing these sync operations wh
Replies
3
Boosts
0
Views
847
Activity
Sep ’25
View with FetchRequest doesnt update on change
Hello guys, this is my first post to this forum and really hope that somebody can help me here. I would highly appreciate every help! I am writing my first app with Swift UI (never used UIKit before) which I want to publish later on. This is also my first app which has CoreData implemented. For example I use the following entities: Family, Person 1 Persons can have 1 Family 1 Family can have many Persons My App is structured as the following: ContentView: Contains a TabView with 2 other views in it. A Settings View and a View with a LazyVGrid. LazyVGrid View: This View shows a GridItem for every Family. I get the Families with the following Fetchrequest: @Environment(.managedObjectContext) private var viewContext // These are the Families from the FetchRequest @FetchRequest(entity: Family.entity(), sortDescriptors: [NSSortDescriptor(keyPath: Family.created, ascending: false)] ) var families: FetchedResults Every GridItem is linking to a FamilyDetailView via NavigationLink. So i pass the family as the followin
Replies
1
Boosts
0
Views
794
Activity
Sep ’25
SwiftData ModelCoders.swift:1069 Unable to decode
Hello Developer Support, I have the following code and the following crash. How can the swift data model unable to decode and yet able to display the decoded value at the same time?! What's missing here? CODE: @Model final class DisplayCache { init(point: MKMapPoint) { self.point = point } var point: MKMapPoint } CRASH SwiftData/ModelCoders.swift:1069: Fatal error: Unable to decode this value MKMapPoint(x: 74358466.66307731, y: 97927933.41833577)
Replies
3
Boosts
0
Views
172
Activity
Sep ’25
CloudKit Sync with TestFlight
I'm working on a new app with SwiftData and now adding CloudKit Sync. Everything is working fine in the simulator against the development CloudKit Schema. I successfully deployed the schema to production. However, the TestFlight builds fail against production. This is what I see in the logs, but I haven't been able to find info on how to fix it. Help appreciated. CoreData+CloudKit: -[NSCloudKitMirroringDelegate _requestAbortedNotInitialized:](2205): - Never successfully initialized and cannot execute request '' due to error: Error Domain=CKErrorDomain Code=2 CKInternalErrorDomain: 1011 UserInfo={ContainerID=, NSDebugDescription=CKInternalErrorDomain: 1011, CKPartialErrors=, RequestUUID=, NSLocalizedDescription=, CKErrorDescription=, NSUnderlyingError=0x1078e9fe0 {Error Domain=CKInternalErrorDomain Code=1011 UserInfo={CKErrorDescription=, NSLocalizedDescription=, CKPartialErrors=}}} CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(1153): : Successfully set up Cloud
Replies
1
Boosts
0
Views
132
Activity
Sep ’25
Reply to iOS 26 SwiftData crash does not happen in iOS 16
The error message seems to indicate a type mis-match, likely the data in your JSON data being a number, while the corresponding SwiftData attribute being a string. That mismatch triggers an error when your app saves the SwiftData store. If you save your SwiftData store immediately after modelContext.insert(decodedResponse), as shown below, you will see the error: func getBestSellerLists() async { ... modelContext.insert(decodedResponse) // Add the following code to save the context and trigger the error. do { try modelContext.save() // This triggers the error. } catch { print(error) } ... } You can probably use the following flow to figure out which piece of data triggers the type mismatch: Add the code snippet above to your project so you can trigger the crash in a controlled way. Replace the JSON data from the remote server with a local JSON file so you can easily change data. Remove part of the data from the JSON file, change your SwiftData models to match the schema, an
Replies
Boosts
Views
Activity
Sep ’25
Reply to How to configure macOS app permission MANUALLY (not GUI)
The modeling tool is called MagicDraw, a UML modeling tool written in Java and originally created by a company No Magic, which was acquired by Dassault Systèmes. I have a long relationship with this company, so I have some insight into the tool, and some source code to support my customization work for special modeling strategies, however I have not enough sources to rebuild the tool on my own. The reason for the many copies is to keep one clean copy and then some copy s in various states of customization. After upgrading to Sequoia from Mojave, I started the clean copy of MagicDraw first, in the hope it would attach all security attributes to it. But unfortunately Sequoia picked one of the customized copies as the one and only entry in Privacy & Security -> Local Network. Since there is no GUI provision in Local Networks to add or remove applications, it requires some hacking (starting and killing of the app, combined with enabling and removing in Local Network) to provide the clean MagicDraw
Replies
Boosts
Views
Activity
Sep ’25
Mutating an array of model objects that is a child of a model object
Hi all, In my SwiftUI / SwiftData / Cloudkit app which is a series of lists, I have a model object called Project which contains an array of model objects called subprojects: final class Project1 { var name: String = @Relationship(deleteRule: .cascade, inverse: Subproject.project) var subprojects : [Subproject]? init(name: String) { self.name = name self.subprojects = [] } } The user will select a project from a list, which will generate a list of subprojects in another list, and if they select a subproject, it will generate a list categories and if the user selects a category it will generate another list of child objects owned by category and on and on. This is the pattern in my app, I'm constantly passing arrays of model objects that are the children of other model objects throughout the program, and I need the user to be able to add and remove things from them. My initial approach was to pass these arrays as bindings so that I'd be able to mutate them. This worked for the most part but
Replies
5
Boosts
0
Views
237
Activity
Sep ’25
Reply to Allow "Browser" to find devices on local networks
I’d like to clarify your overall goal here. Are you planning to ship an app based on Chromium? Or are you building some sort of plug-in that you install within Chromium? This matters because… [quote='800879021, poluyanov, /thread/800879, /profile/poluyanov'] simply overwriting files in the app bundle [/quote] Right. That breaks the seal on the code signature, which causes problems for all privacy subsystems, which rely on the code signature to track the identity of your code, that is, to determine that version N+1 of your app is the ‘same code’ as version N. This is something we call out in TN3179 Understanding local network privacy: To ensure that local network privacy reliably tracks the identity of your macOS program, sign it with an Apple-issued code-signing identity. Most apps don’t suffer from this problem because, when Xcode rebuilds the app, it signs result. If you’ve selected an Apple-issued code-signing identity, the new app has the same designated requirement as the previous app, and thus the OS tr
Replies
Boosts
Views
Activity
Sep ’25
Reply to Mutating an array of model objects that is a child of a model object
@joadan but for self.project.subcategories?.removeAll { $0 == subcategory} you won't know if it didn't removeAll because subcategory didn't exist in the array, or if subcategories was nil to begin with because it didn't load from CloudKit / SwiftData.
Replies
Boosts
Views
Activity
Sep ’25
Reply to Inheritance in SwiftData — Fatal error: Never access a full future backing data
This looks like a known issue related to SwiftData failing to materialize a relationship that has a super class. I’d suggest that you file a feedback report so you can use it to request the latest status of the issue. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Sep ’25
Inheritance in SwiftData — Fatal error: Never access a full future backing data
I'm implementing SwiftData with inheritance in an app. I have an Entity class with a property name. This class is inherited by two other classes: Store and Person. The Entity model has a one-to-many relationship with a Transaction class. I can list all my Entity models in a List with a @Query annotation without a problem. However, then I try to access the name property of an Entity from a Transaction relationship, the app crashes with the following error: Thread 1: Fatal error: Never access a full future backing data - PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(backing: SwiftData.PersistentIdentifier.PersistentIdentifierBacking.managedObjectID(0x96530ce28d41eb63 ))) with Optional(F07E7E23-F8F0-4CC0-B282-270B5EDDC7F3) From my attempts to fix the issue, I noticed that: The crash seems related to the relationships with classes that has inherit from another class, since it only happens there. When I create new data, I can usually acces
Replies
1
Boosts
0
Views
272
Activity
Sep ’25
Reply to Save SwiftData object for model with one to many relationship
Found the issue: In a one to many relationship to be able to enter the one side of the relationship you need to identify the many side, even if you are not entering any values for the many side. In this case the many side is Contracts and a state variable needs to be declared @State private var contracts: [Contract] = [] with an empty array.
Replies
Boosts
Views
Activity
Sep ’25
Save SwiftData object for model with one to many relationship
First the Model: import Foundation import SwiftData //Model for Earned Value Analysis @Model final class CostReport{ var aCWP: Double //Actual Cost of Work Performed var bCWP: Double //Budgeted Cost of Work Performed var bCWS: Double // Budgeted Cost of Work Scheduled var cumACWP: Double// Cumlative Actual Cost of Work Performed var cumBCWP: Double // Cumlative Budgeted Cost of Work Performed var cumBCWS: Double // Cumlative Budgeted Cost of Work Scheduled var startDateOfPeriod: Date var endDateOfPeriod: Date var contract: Contract? init(aCWP: Double = 0.0, bCWP: Double = 0.0, bCWS: Double = 0.0, cumACWP: Double = 0.0, cumBCWP: Double = 0.0, cumBCWS: Double = 0.0, startDateOfPeriod: Date = .now, endDateOfPeriod: Date = .now, contract: Contract) { self.aCWP = aCWP self.bCWP = bCWP self.bCWS = bCWS self.cumACWP = cumACWP self.cumBCWP = cumBCWP self.cumBCWS = cumBCWS self.startDateOfPeriod = startDateOfPeriod self.endDateOfPeriod = endDateOfPeriod self.contract = contract } } @Model //Model for Contract
Replies
4
Boosts
0
Views
246
Activity
Sep ’25
Reply to Save SwiftData object for model with one to many relationship
import SwiftData //Model for Earned Value Analysis The Model @Model final class CostReport{ var aCWP: Double //Actual Cost of Work Performed var bCWP: Double //Budgeted Cost of Work Performed var bCWS: Double // Budgeted Cost of Work Scheduled var cumACWP: Double// Cumlative Actual Cost of Work Performed var cumBCWP: Double // Cumlative Budgeted Cost of Work Performed var cumBCWS: Double // Cumlative Budgeted Cost of Work Scheduled var startDateOfPeriod: Date var endDateOfPeriod: Date var contract: Contract? init(aCWP: Double = 0.0, bCWP: Double = 0.0, bCWS: Double = 0.0, cumACWP: Double = 0.0, cumBCWP: Double = 0.0, cumBCWS: Double = 0.0, startDateOfPeriod: Date = .now, endDateOfPeriod: Date = .now, contract: Contract) { self.aCWP = aCWP self.bCWP = bCWP self.bCWS = bCWS self.cumACWP = cumACWP self.cumBCWP = cumBCWP self.cumBCWS = cumBCWS self.startDateOfPeriod = startDateOfPeriod self.endDateOfPeriod = endDateOfPeriod self.contract = contract } } @Model //Model for Contracts final class Contract{ v
Replies
Boosts
Views
Activity
Sep ’25
Reply to SMAppService Sample Code seems broken
I have noticed that launchd is changing my status to 78 at times which I vaguely remember is a permissions issue but I can't find the relevant documentation anymore. I'm not actually attempting to do anything even remotely privileged in the code yet; the example service is unchanged save for a liberal blanketing of print() calls to try and see if anything is ever running. Nothing ever shows up on the console so I have no clue what would lack permission to run if I'm getting SMAppService.Status.enabled back from the service object. Does the nested launchd job not inherit the parent app's entitlements or something?
Replies
Boosts
Views
Activity
Sep ’25