Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

Reply to SwiftData: Unexpected backing data for snapshot creation
I had that guess too, however, myEntity.isDeleted is false when this occurs. Also, I am fetching the model right before deleting it. Here I have just noticed something weird in the documentation, namely that model(for:) creates an unsaved instance if called with an unknown ID. So I tried the same with registeredModel(for:), but I get the same error https://developer.apple.com/documentation/swiftdata/modelcontext/model(for:)
Oct ’25
SwiftData: Unexpected backing data for snapshot creation
When deleting a SwiftData entity, I sometimes encounter the following error in a document based SwiftUI app: Fatal error: Unexpected backing data for snapshot creation: SwiftData._FullFutureBackingData The deletion happens in a SwiftUI View and the code used to retrieve the entity is standard (the ModelContext is injected from the @Environment): let myEntity = modelContext.model(for: entityIdToDelete) modelContext.delete(myEntity) Unfortunately, I haven't yet managed to isolate this any further in order to come up with a reproducible PoC. Could you give me further information about what this error means?
3
0
255
Oct ’25
Reply to Finding source for SwiftData array behaviour
I am not completely clear what your question is, but based on the description, it seems to be related to the order of SwiftData array, and so I'd start with that. In a SwiftData model that contains an array, the array element can be a Codable type or a SwiftData model, as shown below: @Model class Department { @Relationship(deleteRule: .cascade, inverse: Employee.department) var employees: [Employee] = [Employee]() // Relationship var aliasNames: [String] = [] // `String` is Codable ... } @Model class Employee { var department: Department? ... } Here employees is a SwiftData relationship, and aliasNames is an attribute of a string array. Every time you fetch Department and access the attribute and relationship, the elemet order of department.aliasNames is the same, but that of department.employees is not. The reason is that SwiftData uses Core Data as its default store, and in Core Data, a too-many relationship is expres
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to Present User an error message when SwiftData save fails
Thanks for provide the code. I don't see it has anything that should trigger a failure though. If you can elaborate a bit more about what failure you expect to see, I may take another look. To comment your following description: When I was saving a duplicate field value, it was not failing, it was replacing the current with a new record, thus it remained unique because the old record was replaced. This behavior is as-designed, and is known as upsert. For a model that has a unique attribute, when you add a new object and there already exists another object that has the same value for the unique attribute, SwiftData updates the existing object with the new one. No error will be triggered in this case. For models that don't have any unique attribute, objects are identified by persistentModelID, which is managed by SwiftData. You can add multiple objects that have same values for all the attributes you define, without triggering any conflict. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to Present User an error message when SwiftData save fails
import SwiftData //Model one: type of contract, i.e. Firm Fixed Price, etc @Model final class TypeOfContract { var contracts: [Contract] var typeName: String var typeCode: String var typeDescription: String init(contracts: [Contract], typeName: String = , typeCode: String = , typeDescription: String = ) { self.contracts = contracts self.typeName = typeName self.typeCode = typeCode self.typeDescription = typeDescription } } //Model two: the Contract @Model final class Contract { var contractType: TypeOfContract? var costReports: [CostReport] var contractNumber: String var contractName: String var startDate: Date var endDate: Date var contractValue: Double var contractCompany: String var contractContact: String var contactEmail: String var contactPhone: String var contractNotes: String init(contractType: TypeOfContract? = nil, costReports: [CostReport], contractNumber: String = , contractName: String = , startDate: Date = .now, endDate: Date = .now, contractValue: Double = 0.0, contractCompany: String
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
subscriptionOfferCodes 500 Error
When i create a subscription offer, the following error occurred, and there is no corresponding log ID. { errors: [ { status: 500, code: UNEXPECTED_ERROR, title: An unexpected error occurred., detail: An unexpected error occurred on the server side. If this issue continues, contact us at https://developer.apple.com/contact/. } ] } https://api.appstoreconnect.apple.com/v1/subscriptionOfferCodes The invoked open API: https://api.appstoreconnect.apple.com/v1/subscriptionOfferCodes This is my request data: { data: { type: subscriptionOfferCodes, attributes: { duration: ONE_YEAR, numberOfPeriods: 1, offerMode: PAY_AS_YOU_GO, name: test_error_issue2, customerEligibilities: [ NEW ], offerEligibility: STACK_WITH_INTRO_OFFERS }, relationships: { prices: { data: [ { id: ${sg-30-offerCode}, type: subscriptionOfferCodePrices } ] }, subscription: { data: { id: 6738041235, type: subscriptions } } } }, included: [ { id: ${sg-30-offerCode}, type: subscriptionOfferCodePrices, relationships: { subscriptionPri
0
0
73
Oct ’25
Reply to Macos Tahoe issue launching apps through SSH
On a CI infrastructure, we connect nodes through SSH and launch automated app testing. So, I'm going to start with a very short answer, then try and give a much longer answer. So, the short answer first: open /Applications/Pages.app Great! You should do that! /Applications/Pages.app/Contents/MacOS/ Yes, you really shouldn't do this. Long Answer: Let's start with what this actually does: open /Applications/Pages.app Part of our system’s fundamental design is the idea of execution contexts. If you want to learn more about some of the details, the great classic, TN2083: Daemons and Agents, is probably the best entry point. However, summarizing the most relevant details... First off, for our purposes, there are two relevant execution contexts: The global or system session. This is running all the time and cannot present any kind of user interface. This is where daemons run. User or login sessions (there can be more than one if multiple users are logged in). Logging in creates a login session, and logging out dest
Oct ’25
Present User an error message when SwiftData save fails
Have a data model that sets certain fields as unique. If the user attempts to save a duplicate value, the save fails quietly with no indication to the user that the save failed. The program is on Mac OS 26.0.1 @Environment(.modelContext) var modelContext @Query private var typeOfContracts: [TypeOfContract] @State private var typeName: String = @State private var typeCode: String = @State private var typeDescription: String = @State private var contracts: [Contract] = [] @State private var errorMessage: String? = Data Entered @State private var showAlert: Bool = false var body: some View { Form { Text(Enter New Contract Type) .font(.largeTitle) .foregroundStyle(Color(.green)) .multilineTextAlignment(.center) TextField(Contract Type Name, text: $typeName) .frame(width: 800, height: 40) TextField(Contract Type Code, text: $typeCode) .frame(width: 800, height: 40) Text(Contract Type Description) TextEditor(text: $typeDescription) .frame(width: 800, height: 200) .scrollContentBackground(.hidden) .background(Col
10
0
311
Oct ’25
Reply to Launching MacOS app via Url Scheme
Part 2... That leads to here: and how can I make sure my app will be allowed to update when I need it too. The first thing I'd do here is shift the way you're thinking about this issue from how do I remove/bypass quarantine to how do I make sure my update process always works. You've focussed on quarantine because it's a fairly common edge case; however, the problem with focussing on solving it is: The system’s behavior is opaque and undocumented. This means, as you're already experiencing, it's hard to make this work right at all, and even if you succeed, it's very likely that something will change in the future, leaving you back with the same problem. Quarantine is only one failure source of many. For example, what if the actual problem is that the app is being run from a read-only location like a network share? That second point is what makes this problem so tricky. The full range of valid macOS configuration is so large that it's effectively impossible to fully test or predict. This means you end up trapp
Topic: Safari & Web SubTopic: General
Oct ’25
SwiftData not syncing to CloudKit
I have an app with SwiftData and CloudKit sync enabled, it was working fine but I recently noticed that the sync with CloudKit is not working anymore. All the changes are persisted locally just fine. When running in simulator (iOS 26/iPhone 17 Pro) I get the following error in the console: CoreData+CloudKit: -[NSCloudKitMirroringDelegate recoverFromError:](2317): - Attempting recovery from error: Error Domain=NSCocoaErrorDomain Code=134421 Export encountered an unhandled exception while analyzing history in the store. UserInfo={NSLocalizedFailureReason=Export encountered an unhandled exception while analyzing history in the store., NSUnderlyingException=-[NSEntityDescription objectID]: unrecognized selector sent to instance 0x60000351aec0} I already tried Reseting the environment back to production in CloudKit and Erasing all Contents and Settings in the simulator but I keep getting the same error. Is there something else I can do to fix this?
2
0
214
Oct ’25
Beginner’s question on learning philosophy.
Hello Everyone! I started programming 6 months ago and started Swift / IOS last month. My learning so far has mainly been with Python. I learned a lot of the package ‘SQLAlchemy’, which has very ‘example based’ documentation. If I wanted to learn how to make a many to many relationship, there was a demonstration with code. But going into Swift and Apple packages, I notice most of the documentation is definitions of structures, modifiers, functions, etc. I wanted to make the equivalent of python ‘date times’ in my swift app. I found the section in the documentation “Foundation->Dates & Times”, but I couldn’t figure how to use that in my code. I assume my goal should not be to memorize every Swift and apple functionality by memory to be an app developer. So I would appreciate advice on how to approach this aspect of learning programming.
2
0
544
Oct ’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
Oct ’25
Reply to SwiftData: Unexpected backing data for snapshot creation
I had that guess too, however, myEntity.isDeleted is false when this occurs. Also, I am fetching the model right before deleting it. Here I have just noticed something weird in the documentation, namely that model(for:) creates an unsaved instance if called with an unknown ID. So I tried the same with registeredModel(for:), but I get the same error https://developer.apple.com/documentation/swiftdata/modelcontext/model(for:)
Replies
Boosts
Views
Activity
Oct ’25
SwiftData: Unexpected backing data for snapshot creation
When deleting a SwiftData entity, I sometimes encounter the following error in a document based SwiftUI app: Fatal error: Unexpected backing data for snapshot creation: SwiftData._FullFutureBackingData The deletion happens in a SwiftUI View and the code used to retrieve the entity is standard (the ModelContext is injected from the @Environment): let myEntity = modelContext.model(for: entityIdToDelete) modelContext.delete(myEntity) Unfortunately, I haven't yet managed to isolate this any further in order to come up with a reproducible PoC. Could you give me further information about what this error means?
Replies
3
Boosts
0
Views
255
Activity
Oct ’25
Reply to Finding source for SwiftData array behaviour
I am not completely clear what your question is, but based on the description, it seems to be related to the order of SwiftData array, and so I'd start with that. In a SwiftData model that contains an array, the array element can be a Codable type or a SwiftData model, as shown below: @Model class Department { @Relationship(deleteRule: .cascade, inverse: Employee.department) var employees: [Employee] = [Employee]() // Relationship var aliasNames: [String] = [] // `String` is Codable ... } @Model class Employee { var department: Department? ... } Here employees is a SwiftData relationship, and aliasNames is an attribute of a string array. Every time you fetch Department and access the attribute and relationship, the elemet order of department.aliasNames is the same, but that of department.employees is not. The reason is that SwiftData uses Core Data as its default store, and in Core Data, a too-many relationship is expres
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’25
Finding source for SwiftData array behaviour
Hello Apple Developer Forum, I got the following statement from the AI model. It seems it is also reflecting my real-world experience. Where do I find an official source that fully describes the array on swiftData model behaviour? When a SwiftData model contains an array of value types, such as [String] or [Int], the array's order is preserved
Replies
4
Boosts
0
Views
284
Activity
Oct ’25
Reply to Present User an error message when SwiftData save fails
Thanks for provide the code. I don't see it has anything that should trigger a failure though. If you can elaborate a bit more about what failure you expect to see, I may take another look. To comment your following description: When I was saving a duplicate field value, it was not failing, it was replacing the current with a new record, thus it remained unique because the old record was replaced. This behavior is as-designed, and is known as upsert. For a model that has a unique attribute, when you add a new object and there already exists another object that has the same value for the unique attribute, SwiftData updates the existing object with the new one. No error will be triggered in this case. For models that don't have any unique attribute, objects are identified by persistentModelID, which is managed by SwiftData. You can add multiple objects that have same values for all the attributes you define, without triggering any conflict. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’25
Reply to Present User an error message when SwiftData save fails
import SwiftData //Model one: type of contract, i.e. Firm Fixed Price, etc @Model final class TypeOfContract { var contracts: [Contract] var typeName: String var typeCode: String var typeDescription: String init(contracts: [Contract], typeName: String = , typeCode: String = , typeDescription: String = ) { self.contracts = contracts self.typeName = typeName self.typeCode = typeCode self.typeDescription = typeDescription } } //Model two: the Contract @Model final class Contract { var contractType: TypeOfContract? var costReports: [CostReport] var contractNumber: String var contractName: String var startDate: Date var endDate: Date var contractValue: Double var contractCompany: String var contractContact: String var contactEmail: String var contactPhone: String var contractNotes: String init(contractType: TypeOfContract? = nil, costReports: [CostReport], contractNumber: String = , contractName: String = , startDate: Date = .now, endDate: Date = .now, contractValue: Double = 0.0, contractCompany: String
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’25
subscriptionOfferCodes 500 Error
When i create a subscription offer, the following error occurred, and there is no corresponding log ID. { errors: [ { status: 500, code: UNEXPECTED_ERROR, title: An unexpected error occurred., detail: An unexpected error occurred on the server side. If this issue continues, contact us at https://developer.apple.com/contact/. } ] } https://api.appstoreconnect.apple.com/v1/subscriptionOfferCodes The invoked open API: https://api.appstoreconnect.apple.com/v1/subscriptionOfferCodes This is my request data: { data: { type: subscriptionOfferCodes, attributes: { duration: ONE_YEAR, numberOfPeriods: 1, offerMode: PAY_AS_YOU_GO, name: test_error_issue2, customerEligibilities: [ NEW ], offerEligibility: STACK_WITH_INTRO_OFFERS }, relationships: { prices: { data: [ { id: ${sg-30-offerCode}, type: subscriptionOfferCodePrices } ] }, subscription: { data: { id: 6738041235, type: subscriptions } } } }, included: [ { id: ${sg-30-offerCode}, type: subscriptionOfferCodePrices, relationships: { subscriptionPri
Replies
0
Boosts
0
Views
73
Activity
Oct ’25
Reply to Macos Tahoe issue launching apps through SSH
On a CI infrastructure, we connect nodes through SSH and launch automated app testing. So, I'm going to start with a very short answer, then try and give a much longer answer. So, the short answer first: open /Applications/Pages.app Great! You should do that! /Applications/Pages.app/Contents/MacOS/ Yes, you really shouldn't do this. Long Answer: Let's start with what this actually does: open /Applications/Pages.app Part of our system’s fundamental design is the idea of execution contexts. If you want to learn more about some of the details, the great classic, TN2083: Daemons and Agents, is probably the best entry point. However, summarizing the most relevant details... First off, for our purposes, there are two relevant execution contexts: The global or system session. This is running all the time and cannot present any kind of user interface. This is where daemons run. User or login sessions (there can be more than one if multiple users are logged in). Logging in creates a login session, and logging out dest
Replies
Boosts
Views
Activity
Oct ’25
Reply to Present User an error message when SwiftData save fails
Your code doesn't include the SwiftData model type (TypeOfContract), and hence isn't runnable. If you can provide a runnable code example, with detailed steps to reproduce the issue, I'd be interested in taking a look. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’25
Present User an error message when SwiftData save fails
Have a data model that sets certain fields as unique. If the user attempts to save a duplicate value, the save fails quietly with no indication to the user that the save failed. The program is on Mac OS 26.0.1 @Environment(.modelContext) var modelContext @Query private var typeOfContracts: [TypeOfContract] @State private var typeName: String = @State private var typeCode: String = @State private var typeDescription: String = @State private var contracts: [Contract] = [] @State private var errorMessage: String? = Data Entered @State private var showAlert: Bool = false var body: some View { Form { Text(Enter New Contract Type) .font(.largeTitle) .foregroundStyle(Color(.green)) .multilineTextAlignment(.center) TextField(Contract Type Name, text: $typeName) .frame(width: 800, height: 40) TextField(Contract Type Code, text: $typeCode) .frame(width: 800, height: 40) Text(Contract Type Description) TextEditor(text: $typeDescription) .frame(width: 800, height: 200) .scrollContentBackground(.hidden) .background(Col
Replies
10
Boosts
0
Views
311
Activity
Oct ’25
Reply to Launching MacOS app via Url Scheme
Part 2... That leads to here: and how can I make sure my app will be allowed to update when I need it too. The first thing I'd do here is shift the way you're thinking about this issue from how do I remove/bypass quarantine to how do I make sure my update process always works. You've focussed on quarantine because it's a fairly common edge case; however, the problem with focussing on solving it is: The system’s behavior is opaque and undocumented. This means, as you're already experiencing, it's hard to make this work right at all, and even if you succeed, it's very likely that something will change in the future, leaving you back with the same problem. Quarantine is only one failure source of many. For example, what if the actual problem is that the app is being run from a read-only location like a network share? That second point is what makes this problem so tricky. The full range of valid macOS configuration is so large that it's effectively impossible to fully test or predict. This means you end up trapp
Topic: Safari & Web SubTopic: General
Replies
Boosts
Views
Activity
Oct ’25
Reply to unifiedContacts identifier vs contactRelations identifier
Is there a better channel or documentation to understand the details of relationship between the GUID for unifiedContacts identifier vs contactRelations identifier?
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’25
SwiftData not syncing to CloudKit
I have an app with SwiftData and CloudKit sync enabled, it was working fine but I recently noticed that the sync with CloudKit is not working anymore. All the changes are persisted locally just fine. When running in simulator (iOS 26/iPhone 17 Pro) I get the following error in the console: CoreData+CloudKit: -[NSCloudKitMirroringDelegate recoverFromError:](2317): - Attempting recovery from error: Error Domain=NSCocoaErrorDomain Code=134421 Export encountered an unhandled exception while analyzing history in the store. UserInfo={NSLocalizedFailureReason=Export encountered an unhandled exception while analyzing history in the store., NSUnderlyingException=-[NSEntityDescription objectID]: unrecognized selector sent to instance 0x60000351aec0} I already tried Reseting the environment back to production in CloudKit and Erasing all Contents and Settings in the simulator but I keep getting the same error. Is there something else I can do to fix this?
Replies
2
Boosts
0
Views
214
Activity
Oct ’25
Beginner’s question on learning philosophy.
Hello Everyone! I started programming 6 months ago and started Swift / IOS last month. My learning so far has mainly been with Python. I learned a lot of the package ‘SQLAlchemy’, which has very ‘example based’ documentation. If I wanted to learn how to make a many to many relationship, there was a demonstration with code. But going into Swift and Apple packages, I notice most of the documentation is definitions of structures, modifiers, functions, etc. I wanted to make the equivalent of python ‘date times’ in my swift app. I found the section in the documentation “Foundation->Dates & Times”, but I couldn’t figure how to use that in my code. I assume my goal should not be to memorize every Swift and apple functionality by memory to be an app developer. So I would appreciate advice on how to approach this aspect of learning programming.
Replies
2
Boosts
0
Views
544
Activity
Oct ’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
Oct ’25