Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

NewDocumentButton in DocumentGroupLauchScene crashes for SwiftData Document-Based App
I have a SwiftData document-based app. It is initialized like this: @main struct MyApp: App { @State private var showTemplatePicker = false @State private var documentCreationContinuation: CheckedContinuation? var body: some Scene { DocumentGroup(editing: .myDocument, migrationPlan: MyMigrationPlan.self) { CanvasView() } DocumentGroupLaunchScene(Text(My App)) { NewDocumentButton(New, contentType: .canvasDocument) { try await withCheckedThrowingContinuation { continuation in documentCreationContinuation = continuation showTemplatePicker = true } } .fullScreenCover(isPresented: $showTemplatePicker) { TemplateView(documentCreationContinuation: $documentCreationContinuation) } } background: { Image(BoardVignette) .resizable() } } } extension UTType { static var canvasDocument: UTType { UTType(importedAs: com.example.MyApp.canvas) } } Pressing the New button crashes with: #0 0x00000001d3a6e12c in (1) suspend resume partial function for closure #1 () async -> () in SwiftUI.IdentifiedDocumentGroupDocumen
2
0
143
May ’25
Fetching data with relationships directly faults the relationships even when not accessed
I am using SwiftData to model my data. For that i created a model called OrganizationData that contains various relationships to other entities. My data set is quite large and i am having a big performance issue when fetching all OrganizationData entities. I started debugging and looking at the sql debug log i noticed that when fetching my entities i run into faults for all relationships even when not accessing them. Fetching my entities: let fetchDescriptor = FetchDescriptor() let context = MapperContext(dataManager: self) let organizations = (try modelContainer.mainContext.fetch(fetchDescriptor)) Doing this fetch, also fetches all relationships. Each in a single query, for every OrganizationData entity. CoreData: annotation: to-many relationship fault relationship1 for objectID 0x8aa5249772916e00 fulfilled from database. Got 9 rows CoreData: annotation: to-many relationship fault relationship2 for objectID 0x8aa5249772916e00 fulfilled from database. Go
14
0
454
May ’25
Creating Advanced AppClip Experiences Via API
I'm trying to programmatically create an Advanced AppClip Experience via the API. following the docs https://developer.apple.com/documentation/appstoreconnectapi/app-clips-and-app-clip-experiences I have created the header image. But when I try to create the experience I can not figure out a) how to create a localisationID to be included in the relationships object b) how to get the included object to be recognised Any one have experience or can offer help?
1
0
128
May ’25
SwiftData/ModelSnapshot.swift:46: Fatal error: A ModelSnapshot must be initialized with a known-keys dictionary
I'm running into a crash when trying to delete an item from a list that's loaded using SwiftData. The app works fine when selecting or displaying the data, but the moment I confirm a deletion, it crashes with this error: SwiftData/ModelSnapshot.swift:46: Fatal error: A ModelSnapshot must be initialized with a known-keys dictionary This happens right after I delete an item from the list using modelContext.delete(). I’ve double-checked that the item exists and is valid, and I'm not sure what I'm doing wrong. The data is loaded using @Query and everything seems normal until deletion. For further information, I have tried this on a new IOS project where I have one super Model class with a cascading relationship on a child class. When trying to delete the parent class while connected to one or more children, it still gives me the error. The same thing is happening with my original project. Class A has a relationship (cascading) with Class B. Attempting to delete Class A while th
2
0
225
May ’25
Reply to How are child processes sandboxed?
Hello, I have a follow up question. It is by design the sandbox gets inherited when running a command line tool using the Process.run() from an application signed by a different Team ID? Eg. the PowerPoint app authored by the Team ID UBF8T346G9 runs a tool signed by Team ID 44X73QA89R (a different developer team) and the tools inherit's the PowerPoint app's sandbox.
Topic: Privacy & Security SubTopic: General Tags:
May ’25
Apple Connect API
Hello, can any help to set a price change to any of our In-Apps programmaticly(C#). I'm have no problem to create the token and i get positive results for GET calls (like In-App purchase data or Apple PriceTemplates). My Get call is a simple HttpClient GetAsync(id) so I supposed I need a HttpClient PostAsync(url, content). The result is a 404 NotFound which is no error shown for this call. I searched a lot to fix the error but I found nothing that is explaining this error. My content is created like this: var content = new StringContent(jsonmodel, Encoding.UTF8, application/json); My URL: https://api.appstoreconnect.apple.com/v1/inAppPriceSchedules My JsonModel: { data: { relationships: { baseTerritory: { data: { id: DEU, type: territories } }, inAppPurchase: { data: { id: 6448129561, type: inAppPurchases } }, manualPrices: { data: [ { id: eyJzIjoiNjQ0ODEyOTU2MSIsInQiOiJERVUiLCJwIjoiMTAxMjcifQ, type: inAppPurchasePrices } ] } }, type: inAppPurchases, id: eyJzIjoiNjQ0ODEyOTU2MSIsInQiOiJERVUiLCJwIjoiMT
0
0
105
May ’25
Reply to SwiftData with shared and private containers
I’m hoping this year will bring sharing to swiftdata. I’m in so much pain between outdated playgrounds and ai trained on old sets it’s really hard… i managed to use CloudKit using core data then realised this was still maintaining the two framework and not having one. so I started back with swiftdata and a whole datamanager in the middle to create CKrecords from swiftdata when shared but got way too complex. im just going to wait for a solution From wwdc one day
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’25
Reply to Error when running a modelContext rollback
Hi - I am getting the same error, but on modelContext.delete(). I went through checking all the relationship ids, and they are all fine. All models seem to be registered and can be accessed through relationships, fetches or @Query. . I have had some success with SwiftData, using in a semi-production app for about a year. I have never seen this error message before. This seems like a new bug to me.
May ’25
SwiftData shared across apps?
The stuff I've found by searching has confused me, so hopefully someone can help simplify it for me? I have an app (I use it for logging which books I've given away), and I could either add a bunch of things to the app, or I could have another app (possibly a CLI tool) to generate some reports I'd like.
0
0
86
May ’25
Compiler - method linking issue.
Issue: During app execution, the intended method is not being called; instead, the method preceding (written above the intended method) is being executed. For Example: //In my case the ViewController class is at 3rd level of inheritance. class ViewController: UIViewController { func methodA() { print(methodA) } func methodB() { print(methodB) } } let vc = ViewController() vc.methodB() Output: //methodA Expected: //methodB Observations: Recent code changes have revealed that enabling the below Swift-6 flag leads to this linking issue. When this flag is commented out, the problem disappears. .enableUpcomingFeature(InternalImportsByDefault) Additionally, moving the intended method into an extension of the same class resolves the issue when the flag is enabled. Conclusion: To resolve the issue: Comment out the Swift-6 flag. Alternatively, move the method into an extension of the same class, which addresses the issue for this specific case. I had similar issue in other class where it crashes with message
2
0
165
Apr ’25
Help getting elements from SwiftData in AppIntent for widget
Hello, I am trying to get the elements from my SwiftData databse in the configuration for my widget. The SwiftData model is the following one: @Model class CountdownEvent { @Attribute(.unique) var id: UUID var title: String var date: Date @Attribute(.externalStorage) var image: Data init(id: UUID, title: String, date: Date, image: Data) { self.id = id self.title = title self.date = date self.image = image } } And, so far, I have tried the following thing: AppIntent.swift struct ConfigurationAppIntent: WidgetConfigurationIntent { static var title: LocalizedStringResource { Configuration } static var description: IntentDescription { This is an example widget. } // An example configurable parameter. @Parameter(title: Countdown) var countdown: CountdownEntity? } Countdowns.swift, this is the file with the widget view struct Provider: AppIntentTimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date(), configuration: ConfigurationAppIntent()) } func snap
0
0
168
Apr ’25
Lists, Generics, Views, Navigation Link, SwiftData - ForEach can't pass a binding anymore.
I'm trying out putting most of my business logic in a Protocol that my @Model can conform to, but I'm running into a SwiftUI problem with a Binding that does not get magically offered up like it does when it the subview is not generic. I have a pretty basic List with a ForEach that now can't properly pass to a generic view based on a protocol. When I try to make a binding manually in the row it says that item is immutable... but that also doesn't help me with the NavigationLink? Which is seeing the Binding not the ? But before when the subview was concrete to Thing, it took in the and made its own Binding once it hit the view. I'm unclear on precisely where the change happens and what I can do to work around it. Before I go rearchitecting everything... is there a fix to get the NavigationLink to take on the object like before? What needs to be different? I've tried a number of crazy inits on the subview and they all seem to come back to saying either it can't figure out how to pass the type or I'm trying to u
4
0
205
Apr ’25
Reply to How to import large data from Server and save it to Swift Data
One way would be to perform the import in the background in a @ModelActor. Something like this: @ModelActor actor ImportService { func import(data: [Data]) throws { for date in data { let model = Model(/* ... */) modelContext.insert(model) } try modelContext.save() } } This way the import will not block the UI, and the imported data will only be visible in the UI after modelContext.save() is called. I haven't used SwiftData in a real-world app yet, however, so do be careful. For example I don't know if SwiftData will keep the models in memory until save() is called, so you might have to save more frequently. But even then, the UI will not update for every newly inserted model but only when you choose.
Apr ’25
NewDocumentButton in DocumentGroupLauchScene crashes for SwiftData Document-Based App
I have a SwiftData document-based app. It is initialized like this: @main struct MyApp: App { @State private var showTemplatePicker = false @State private var documentCreationContinuation: CheckedContinuation? var body: some Scene { DocumentGroup(editing: .myDocument, migrationPlan: MyMigrationPlan.self) { CanvasView() } DocumentGroupLaunchScene(Text(My App)) { NewDocumentButton(New, contentType: .canvasDocument) { try await withCheckedThrowingContinuation { continuation in documentCreationContinuation = continuation showTemplatePicker = true } } .fullScreenCover(isPresented: $showTemplatePicker) { TemplateView(documentCreationContinuation: $documentCreationContinuation) } } background: { Image(BoardVignette) .resizable() } } } extension UTType { static var canvasDocument: UTType { UTType(importedAs: com.example.MyApp.canvas) } } Pressing the New button crashes with: #0 0x00000001d3a6e12c in (1) suspend resume partial function for closure #1 () async -> () in SwiftUI.IdentifiedDocumentGroupDocumen
Replies
2
Boosts
0
Views
143
Activity
May ’25
Fetching data with relationships directly faults the relationships even when not accessed
I am using SwiftData to model my data. For that i created a model called OrganizationData that contains various relationships to other entities. My data set is quite large and i am having a big performance issue when fetching all OrganizationData entities. I started debugging and looking at the sql debug log i noticed that when fetching my entities i run into faults for all relationships even when not accessing them. Fetching my entities: let fetchDescriptor = FetchDescriptor() let context = MapperContext(dataManager: self) let organizations = (try modelContainer.mainContext.fetch(fetchDescriptor)) Doing this fetch, also fetches all relationships. Each in a single query, for every OrganizationData entity. CoreData: annotation: to-many relationship fault relationship1 for objectID 0x8aa5249772916e00 fulfilled from database. Got 9 rows CoreData: annotation: to-many relationship fault relationship2 for objectID 0x8aa5249772916e00 fulfilled from database. Go
Replies
14
Boosts
0
Views
454
Activity
May ’25
Creating Advanced AppClip Experiences Via API
I'm trying to programmatically create an Advanced AppClip Experience via the API. following the docs https://developer.apple.com/documentation/appstoreconnectapi/app-clips-and-app-clip-experiences I have created the header image. But when I try to create the experience I can not figure out a) how to create a localisationID to be included in the relationships object b) how to get the included object to be recognised Any one have experience or can offer help?
Replies
1
Boosts
0
Views
128
Activity
May ’25
SwiftData/ModelSnapshot.swift:46: Fatal error: A ModelSnapshot must be initialized with a known-keys dictionary
I'm running into a crash when trying to delete an item from a list that's loaded using SwiftData. The app works fine when selecting or displaying the data, but the moment I confirm a deletion, it crashes with this error: SwiftData/ModelSnapshot.swift:46: Fatal error: A ModelSnapshot must be initialized with a known-keys dictionary This happens right after I delete an item from the list using modelContext.delete(). I’ve double-checked that the item exists and is valid, and I'm not sure what I'm doing wrong. The data is loaded using @Query and everything seems normal until deletion. For further information, I have tried this on a new IOS project where I have one super Model class with a cascading relationship on a child class. When trying to delete the parent class while connected to one or more children, it still gives me the error. The same thing is happening with my original project. Class A has a relationship (cascading) with Class B. Attempting to delete Class A while th
Replies
2
Boosts
0
Views
225
Activity
May ’25
Reply to How are child processes sandboxed?
Hello, I have a follow up question. It is by design the sandbox gets inherited when running a command line tool using the Process.run() from an application signed by a different Team ID? Eg. the PowerPoint app authored by the Team ID UBF8T346G9 runs a tool signed by Team ID 44X73QA89R (a different developer team) and the tools inherit's the PowerPoint app's sandbox.
Topic: Privacy & Security SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’25
Apple Connect API
Hello, can any help to set a price change to any of our In-Apps programmaticly(C#). I'm have no problem to create the token and i get positive results for GET calls (like In-App purchase data or Apple PriceTemplates). My Get call is a simple HttpClient GetAsync(id) so I supposed I need a HttpClient PostAsync(url, content). The result is a 404 NotFound which is no error shown for this call. I searched a lot to fix the error but I found nothing that is explaining this error. My content is created like this: var content = new StringContent(jsonmodel, Encoding.UTF8, application/json); My URL: https://api.appstoreconnect.apple.com/v1/inAppPriceSchedules My JsonModel: { data: { relationships: { baseTerritory: { data: { id: DEU, type: territories } }, inAppPurchase: { data: { id: 6448129561, type: inAppPurchases } }, manualPrices: { data: [ { id: eyJzIjoiNjQ0ODEyOTU2MSIsInQiOiJERVUiLCJwIjoiMTAxMjcifQ, type: inAppPurchasePrices } ] } }, type: inAppPurchases, id: eyJzIjoiNjQ0ODEyOTU2MSIsInQiOiJERVUiLCJwIjoiMT
Replies
0
Boosts
0
Views
105
Activity
May ’25
Reply to SwiftData with shared and private containers
I’m hoping this year will bring sharing to swiftdata. I’m in so much pain between outdated playgrounds and ai trained on old sets it’s really hard… i managed to use CloudKit using core data then realised this was still maintaining the two framework and not having one. so I started back with swiftdata and a whole datamanager in the middle to create CKrecords from swiftdata when shared but got way too complex. im just going to wait for a solution From wwdc one day
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’25
Reply to Lists, Generics, Views, Navigation Link, SwiftData - ForEach can't pass a binding anymore.
FWIW, I've made a cleaner version of what I think ends up being the crux of the problem (Leaves out SwiftData and Navigation) https://developer.apple.com/forums/thread/783142
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’25
Reply to Error when running a modelContext rollback
Hi - I am getting the same error, but on modelContext.delete(). I went through checking all the relationship ids, and they are all fine. All models seem to be registered and can be accessed through relationships, fetches or @Query. . I have had some success with SwiftData, using in a semi-production app for about a year. I have never seen this error message before. This seems like a new bug to me.
Replies
Boosts
Views
Activity
May ’25
SwiftData shared across apps?
The stuff I've found by searching has confused me, so hopefully someone can help simplify it for me? I have an app (I use it for logging which books I've given away), and I could either add a bunch of things to the app, or I could have another app (possibly a CLI tool) to generate some reports I'd like.
Replies
0
Boosts
0
Views
86
Activity
May ’25
Error when running a modelContext rollback
I'm getting the following error message when executing the rollback method in a modelContext, what could be causing this ? SwiftData/ModelSnapshot.swift:46: Fatal error: A ModelSnapshot must be initialized with a known-keys dictionary
Replies
5
Boosts
0
Views
172
Activity
May ’25
Compiler - method linking issue.
Issue: During app execution, the intended method is not being called; instead, the method preceding (written above the intended method) is being executed. For Example: //In my case the ViewController class is at 3rd level of inheritance. class ViewController: UIViewController { func methodA() { print(methodA) } func methodB() { print(methodB) } } let vc = ViewController() vc.methodB() Output: //methodA Expected: //methodB Observations: Recent code changes have revealed that enabling the below Swift-6 flag leads to this linking issue. When this flag is commented out, the problem disappears. .enableUpcomingFeature(InternalImportsByDefault) Additionally, moving the intended method into an extension of the same class resolves the issue when the flag is enabled. Conclusion: To resolve the issue: Comment out the Swift-6 flag. Alternatively, move the method into an extension of the same class, which addresses the issue for this specific case. I had similar issue in other class where it crashes with message
Replies
2
Boosts
0
Views
165
Activity
Apr ’25
Help getting elements from SwiftData in AppIntent for widget
Hello, I am trying to get the elements from my SwiftData databse in the configuration for my widget. The SwiftData model is the following one: @Model class CountdownEvent { @Attribute(.unique) var id: UUID var title: String var date: Date @Attribute(.externalStorage) var image: Data init(id: UUID, title: String, date: Date, image: Data) { self.id = id self.title = title self.date = date self.image = image } } And, so far, I have tried the following thing: AppIntent.swift struct ConfigurationAppIntent: WidgetConfigurationIntent { static var title: LocalizedStringResource { Configuration } static var description: IntentDescription { This is an example widget. } // An example configurable parameter. @Parameter(title: Countdown) var countdown: CountdownEntity? } Countdowns.swift, this is the file with the widget view struct Provider: AppIntentTimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date(), configuration: ConfigurationAppIntent()) } func snap
Replies
0
Boosts
0
Views
168
Activity
Apr ’25
Lists, Generics, Views, Navigation Link, SwiftData - ForEach can't pass a binding anymore.
I'm trying out putting most of my business logic in a Protocol that my @Model can conform to, but I'm running into a SwiftUI problem with a Binding that does not get magically offered up like it does when it the subview is not generic. I have a pretty basic List with a ForEach that now can't properly pass to a generic view based on a protocol. When I try to make a binding manually in the row it says that item is immutable... but that also doesn't help me with the NavigationLink? Which is seeing the Binding not the ? But before when the subview was concrete to Thing, it took in the and made its own Binding once it hit the view. I'm unclear on precisely where the change happens and what I can do to work around it. Before I go rearchitecting everything... is there a fix to get the NavigationLink to take on the object like before? What needs to be different? I've tried a number of crazy inits on the subview and they all seem to come back to saying either it can't figure out how to pass the type or I'm trying to u
Replies
4
Boosts
0
Views
205
Activity
Apr ’25
Reply to How to import large data from Server and save it to Swift Data
One way would be to perform the import in the background in a @ModelActor. Something like this: @ModelActor actor ImportService { func import(data: [Data]) throws { for date in data { let model = Model(/* ... */) modelContext.insert(model) } try modelContext.save() } } This way the import will not block the UI, and the imported data will only be visible in the UI after modelContext.save() is called. I haven't used SwiftData in a real-world app yet, however, so do be careful. For example I don't know if SwiftData will keep the models in memory until save() is called, so you might have to save more frequently. But even then, the UI will not update for every newly inserted model but only when you choose.
Replies
Boosts
Views
Activity
Apr ’25