Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

api.appstoreconnect.apple.com/v1/analyticsReportRequests Endpoint always returns 401 error
Hi all, I am facing an issue with the api.appstoreconnect.apple.com/v1/analyticsReportRequests endpoint. I always get a 401 error when making POST requests to it. The JWT is generated with a team key having Admin access and it works when I make GET requests, so calling api.appstoreconnect.apple.com/v1/apps is successful for example. The body of the POST request is data: { type: analyticsReportRequests, attributes: { accessType: ONGOING }, relationships: { app: { data: { type: apps, id: my_app_id } } } } } Anyone else with the same problem or with some idea on what I might be doing wrong. Many thanks in advance Symeon
1
0
445
Feb ’25
#Predicate doesn't work with enum
Problem The following code doesn't work: let predicate = #Predicate { car in car.size == size //This doesn't work } Console Error Query encountered an error: SwiftData.SwiftDataError(_error: SwiftData.SwiftDataError._Error.unsupportedPredicate) Root cause Size is an enum, #Predicate works with other type such as String however doesn't work with enum Enum value is saved however is not filtered by #Predicate Environment Xcode: 15.0 (15A240d) - App Store macOS: 14.0 (23A339) - Release Candidate Steps to reproduce Run the app on iOS 17 or macOS Sonoma Press the Add button Notice that the list remains empty Expected behaviour List should show the newly created small car Actual behaviour List remains empty inspite of successfully creating the small car. Feedback FB13194334 Code Size enum Size: String, Codable { case small case medium case large } Car import SwiftData @Model class Car { let id: UUID let name: String let size: Size init( id: UUID, name: String, size: Size ) { self.id = id self.name = name se
6
0
2.4k
May ’25
Reply to #Predicate doesn't work with enum
I really hope this gets addressed in #WWDC25. Using a rawValue, you need to hardcode the rawValue, even the below wouldn't compile. #Predicate { $0.statusRawValue == Status.onTime.rawValue } Error: Key path cannot refer to enum case 'status' If the intent of SwiftData is to be modern and not expose the constraints of SQLite, then more needs to be done to improve support more swift types. Using a #Predicate seems like a blackbox, it works for simple primitive type comparisons but doesn't even work when trying to compare with something like Status.onTime.rawValue
May ’25
Shortcuts: Invalid action metadata
I have a habit tracker app that uses App Intents and Shortcuts. The app uses SwiftData to persist data, just in case that's important. One of the shortcuts serves to log habits. However, when the app has been in the background for a good while (over an hour or so), that particular shortcut always fails when I try to run it in the Shortcuts app with the system error Invalid action metadata caused by a bug in the host app. The app has a total of 9 shortcuts, and it's just this one particular shortcut that seems to be failing – the others continue to run without any issues even after the app has been in the background for a long time. The app intent/shortcut that is problematic is the one called HabitEntryAppIntent. For example purposes, I've also included one of the non-problematic intents in the code snippet below called HabitEntryCounterForTodayAppIntent. Both of these intents have one @Parameter value of type HabitEntity. I'll post code snippets in the replies because the character limit is not larg
2
0
183
May ’25
Reply to SwiftData crash on fetch
Apple DTS asked me for a link to the forums, so I'm adding what I know, and send them here. The crash is hard to reproduce, so this is what I know as of now: My app is a SwiftUI-app, with SwiftData I create the ModelContainer in the App-structure: var modelContainer: ModelContainer = { let modelContainer: ModelContainer let schema = Schema(versionedSchema: SchemaV7.self) let config = ModelConfiguration(cloudKitDatabase: .none) do { modelContainer = try ModelContainer( for: schema, migrationPlan: MigrationPlan.self, configurations: config ) } catch { Logger().error(Error creating model container: (error.localizedDescription)) preconditionFailure(Failed to create model container) } return modelContainer }() When I add a new Schema, the migration completes successfully, but for some users (not all), the app crashes. If I delete the app and install the same app but with no database, the app runs as normal. Migrations are done as custom migration steps, to provide logging options, but the crash happens st
May ’25
macOS SwiftData app never syncs with CloudKit
I'm using SwiftData with CloutKit with a very simple app. Data syncs between iOS, iPadOS, and visionOS, but not macOS. From what I can tell, macOS is never getting CK messages unless I'm running the app from Xcode. I can listen for the CK messages and show a line in a debug overlay. This works perfectly when I run from Xcode. I can see the notifications and see updates in my app. However, if I just launch the app outside of Xcode I will never see any changes or notifications. It is as if the Mac app never even tries to contact CloudKit. Schema has been deployed in the CloudKit console. The app is based on the multi-platform Xcode template. Again, only the macOS version has this issue. Is there some extra permission or setting I need to set up in order to use CloudKit on macOS? @State private var publisher = NotificationCenter.default.publisher(for: NSPersistentCloudKitContainer.eventChangedNotification).receive(on: DispatchQueue.main) .onReceive(publisher) { notification in // Listen for changes in C
1
0
206
May ’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
2
0
143
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
May ’25
Reply to Using App Intents in Live Activity to Pause a Timer
The solution is found. To use buttons in LA or Dynamic Island, it shouldn’t be AppIntent, it should be LiveActivityIntent. struct PauseIntent: LiveActivityIntent { // followed by the rest of the code } either load the user defaults data that is linked with App Group or use SwiftData/CoreData, inject model container, and save the updated state there. Then update the live activity, the LA or Dynamic Island will show the updated ContentState. When returning to the app, reload the data from the data store and rebuild the necessary view models.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’25
Keep ScrollView position when adding items on the top
I am using a LayzVStack embedded into a ScrollView. The list items are fetched from a core data store by using a @FetchResult or I tested it also with the new @Query command coming with SwiftData. The list has one hundred items 1, 2, 3, ..., 100. The user scrolled the ScrollView so that items 50, 51, ... 60 are visible on screen. Now new data will be fetched from the server and updates the CoreData or SwiftData model. When I add new items to the end of the list (e.g 101, 102, 103, ...) then the ScrollView is keeping its position. Opposite to this when I add new items to the top (0, -1, -2, -3, ...) then the ScrollView scrolls down. Is there a way with the new SwiftData and SwiftUI ScrollView modifiers to update my list model without scrolling like with UIKit where you can query and set the scroll offset pixel wise?
8
0
9.9k
May ’25
How are child processes sandboxed?
My app is sandboxed (and cannot open or write any file). I was curious what happened to child processes. I had my app execute a bash script (that just writes to a file). The behaviour was expected: the script, launched by my sandboxed app, was sandboxed too.However, when I tried to have my app launch another app (not mine), the child app was not sandboxed. I was curious what was different?I launch my script with[task setLaunchPath: @/bin/bash];[task setArguments:@[@path/to/script.sh]];[task launch];and my app with[task setLaunchPath: @/usr/bin/open];[task setArguments:@[@-a, @/Applications/some.app]];[task launch];Note that the same problem happens when launching the app with [[NSWorkspace sharedWorkspace] launchApplication:@/Applications/some.app]; and with posix_spawn.Apple's docmentions that child processes should inherit sandbox properties, but also mentions that helper apps should include some entitlements properties to do so.What behaviour should we see? Also, how could I make child processes inherit
3
0
3.1k
Oct ’19
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
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
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
May ’25
api.appstoreconnect.apple.com/v1/analyticsReportRequests Endpoint always returns 401 error
Hi all, I am facing an issue with the api.appstoreconnect.apple.com/v1/analyticsReportRequests endpoint. I always get a 401 error when making POST requests to it. The JWT is generated with a team key having Admin access and it works when I make GET requests, so calling api.appstoreconnect.apple.com/v1/apps is successful for example. The body of the POST request is data: { type: analyticsReportRequests, attributes: { accessType: ONGOING }, relationships: { app: { data: { type: apps, id: my_app_id } } } } } Anyone else with the same problem or with some idea on what I might be doing wrong. Many thanks in advance Symeon
Replies
1
Boosts
0
Views
445
Activity
Feb ’25
#Predicate doesn't work with enum
Problem The following code doesn't work: let predicate = #Predicate { car in car.size == size //This doesn't work } Console Error Query encountered an error: SwiftData.SwiftDataError(_error: SwiftData.SwiftDataError._Error.unsupportedPredicate) Root cause Size is an enum, #Predicate works with other type such as String however doesn't work with enum Enum value is saved however is not filtered by #Predicate Environment Xcode: 15.0 (15A240d) - App Store macOS: 14.0 (23A339) - Release Candidate Steps to reproduce Run the app on iOS 17 or macOS Sonoma Press the Add button Notice that the list remains empty Expected behaviour List should show the newly created small car Actual behaviour List remains empty inspite of successfully creating the small car. Feedback FB13194334 Code Size enum Size: String, Codable { case small case medium case large } Car import SwiftData @Model class Car { let id: UUID let name: String let size: Size init( id: UUID, name: String, size: Size ) { self.id = id self.name = name se
Replies
6
Boosts
0
Views
2.4k
Activity
May ’25
Reply to #Predicate doesn't work with enum
I really hope this gets addressed in #WWDC25. Using a rawValue, you need to hardcode the rawValue, even the below wouldn't compile. #Predicate { $0.statusRawValue == Status.onTime.rawValue } Error: Key path cannot refer to enum case 'status' If the intent of SwiftData is to be modern and not expose the constraints of SQLite, then more needs to be done to improve support more swift types. Using a #Predicate seems like a blackbox, it works for simple primitive type comparisons but doesn't even work when trying to compare with something like Status.onTime.rawValue
Replies
Boosts
Views
Activity
May ’25
Shortcuts: Invalid action metadata
I have a habit tracker app that uses App Intents and Shortcuts. The app uses SwiftData to persist data, just in case that's important. One of the shortcuts serves to log habits. However, when the app has been in the background for a good while (over an hour or so), that particular shortcut always fails when I try to run it in the Shortcuts app with the system error Invalid action metadata caused by a bug in the host app. The app has a total of 9 shortcuts, and it's just this one particular shortcut that seems to be failing – the others continue to run without any issues even after the app has been in the background for a long time. The app intent/shortcut that is problematic is the one called HabitEntryAppIntent. For example purposes, I've also included one of the non-problematic intents in the code snippet below called HabitEntryCounterForTodayAppIntent. Both of these intents have one @Parameter value of type HabitEntity. I'll post code snippets in the replies because the character limit is not larg
Replies
2
Boosts
0
Views
183
Activity
May ’25
Reply to SwiftData crash on fetch
Apple DTS asked me for a link to the forums, so I'm adding what I know, and send them here. The crash is hard to reproduce, so this is what I know as of now: My app is a SwiftUI-app, with SwiftData I create the ModelContainer in the App-structure: var modelContainer: ModelContainer = { let modelContainer: ModelContainer let schema = Schema(versionedSchema: SchemaV7.self) let config = ModelConfiguration(cloudKitDatabase: .none) do { modelContainer = try ModelContainer( for: schema, migrationPlan: MigrationPlan.self, configurations: config ) } catch { Logger().error(Error creating model container: (error.localizedDescription)) preconditionFailure(Failed to create model container) } return modelContainer }() When I add a new Schema, the migration completes successfully, but for some users (not all), the app crashes. If I delete the app and install the same app but with no database, the app runs as normal. Migrations are done as custom migration steps, to provide logging options, but the crash happens st
Replies
Boosts
Views
Activity
May ’25
macOS SwiftData app never syncs with CloudKit
I'm using SwiftData with CloutKit with a very simple app. Data syncs between iOS, iPadOS, and visionOS, but not macOS. From what I can tell, macOS is never getting CK messages unless I'm running the app from Xcode. I can listen for the CK messages and show a line in a debug overlay. This works perfectly when I run from Xcode. I can see the notifications and see updates in my app. However, if I just launch the app outside of Xcode I will never see any changes or notifications. It is as if the Mac app never even tries to contact CloudKit. Schema has been deployed in the CloudKit console. The app is based on the multi-platform Xcode template. Again, only the macOS version has this issue. Is there some extra permission or setting I need to set up in order to use CloudKit on macOS? @State private var publisher = NotificationCenter.default.publisher(for: NSPersistentCloudKitContainer.eventChangedNotification).receive(on: DispatchQueue.main) .onReceive(publisher) { notification in // Listen for changes in C
Replies
1
Boosts
0
Views
206
Activity
May ’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
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
May ’25
Reply to Using App Intents in Live Activity to Pause a Timer
The solution is found. To use buttons in LA or Dynamic Island, it shouldn’t be AppIntent, it should be LiveActivityIntent. struct PauseIntent: LiveActivityIntent { // followed by the rest of the code } either load the user defaults data that is linked with App Group or use SwiftData/CoreData, inject model container, and save the updated state there. Then update the live activity, the LA or Dynamic Island will show the updated ContentState. When returning to the app, reload the data from the data store and rebuild the necessary view models.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’25
Keep ScrollView position when adding items on the top
I am using a LayzVStack embedded into a ScrollView. The list items are fetched from a core data store by using a @FetchResult or I tested it also with the new @Query command coming with SwiftData. The list has one hundred items 1, 2, 3, ..., 100. The user scrolled the ScrollView so that items 50, 51, ... 60 are visible on screen. Now new data will be fetched from the server and updates the CoreData or SwiftData model. When I add new items to the end of the list (e.g 101, 102, 103, ...) then the ScrollView is keeping its position. Opposite to this when I add new items to the top (0, -1, -2, -3, ...) then the ScrollView scrolls down. Is there a way with the new SwiftData and SwiftUI ScrollView modifiers to update my list model without scrolling like with UIKit where you can query and set the scroll offset pixel wise?
Replies
8
Boosts
0
Views
9.9k
Activity
May ’25
How are child processes sandboxed?
My app is sandboxed (and cannot open or write any file). I was curious what happened to child processes. I had my app execute a bash script (that just writes to a file). The behaviour was expected: the script, launched by my sandboxed app, was sandboxed too.However, when I tried to have my app launch another app (not mine), the child app was not sandboxed. I was curious what was different?I launch my script with[task setLaunchPath: @/bin/bash];[task setArguments:@[@path/to/script.sh]];[task launch];and my app with[task setLaunchPath: @/usr/bin/open];[task setArguments:@[@-a, @/Applications/some.app]];[task launch];Note that the same problem happens when launching the app with [[NSWorkspace sharedWorkspace] launchApplication:@/Applications/some.app]; and with posix_spawn.Apple's docmentions that child processes should inherit sandbox properties, but also mentions that helper apps should include some entitlements properties to do so.What behaviour should we see? Also, how could I make child processes inherit
Replies
3
Boosts
0
Views
3.1k
Activity
Oct ’19
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
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
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
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