Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

Reply to Modifying an associated value of an existing enum instance
Thank you @DTS Engineer , this is what the rest of the enum cases, and its computed properties, look like: enum FilterItem: Hashable { case work(isSelected: Bool) case family(isSelected: Bool) case health(isSelected: Bool) case social(isSelected: Bool) case energetic(isSelected: Bool) case tired(isSelected: Bool) case restless(isSelected: Bool) case heavy(isSelected: Bool) case numb(isSelected: Bool) case calm(isSelected: Bool) case tense(isSelected: Bool) case light(isSelected: Bool) case racing(isSelected: Bool) case focused(isSelected: Bool) case confused(isSelected: Bool) case overthinking(isSelected: Bool) case blank(isSelected: Bool) case reflective(isSelected: Bool) case head(isSelected: Bool) case neck(isSelected: Bool) case chest(isSelected: Bool) case shoulders(isSelected: Bool) case arms(isSelected: Bool) case solarPlexus(isSelected: Bool) case stomach(isSelected: Bool) case lowerAbdomen(isSelected: Bool) case legs(isSelected: Bool) case wholeBody(isSelected: Bool) var filterName: String { switch s
Jul ’25
SwiftData Background Fetching?
Hi, I am experiencing main thread freezes from fetching on Main Actor. Attempting to move the function to a background thread, but whenever I reference the TestModel in a nonisolated context or in another model actor, I get this warning: Main actor-isolated conformance of 'TestModel' to 'PersistentModel' cannot be used in actor-isolated context; this is an error in the Swift 6 language mode Is there a way to do this correctly? Recreation, warning on line 13: class TestModel { var property: Bool = true init() {} } struct SendableTestModel: Sendable { let property: Bool } @ModelActor actor BackgroundActor { func fetch() throws -> [SendableTestModel] { try modelContext.fetch(FetchDescriptor()).map { SendableTestModel(property: $0.property) } } }
1
0
145
Jul ’25
Reply to SwiftData Class Inheritance
Check out the talk for SwiftData to get some insight on when you should harness Class Inheritance: https://developer.apple.com/videos/play/wwdc2025/291/ As for the depth and width of your Model Graph, it really depends on the full Schema and how the data is partitioned for the particular use cases.
Jul ’25
SwiftData Class Inheritance
Hi, I'm considering using the new SwiftData class inheritance for a new app I'm building. I have a few questions: Is it working well enough for production? I have a number of different object types in my app. Some of them are very similar, and there's always a balance to be struck when it comes to splitting them into different types using class inheritance. Are there some good advice on when to use multiple classes instead of squeezing my object types into a single class? Is there advice against using class inheritance in multiple levels (3-4)? Claes
1
0
134
Jul ’25
Consequences of incorrect VersionedSchema.versionIdentifier
About 4 months ago, I shipped the first version of my app with 4 versioned schemas that, unintentionally, had the same versionIdentifier of 1.2.0 in 2 of them: V1: 1.0.0 V2: 1.1.0 V3: 1.2.0 V4: 1.2.0 They are ordered correctly in the MigrationPlan, and they are all lightweight. Migration works, SwiftData doesn't crash on init and I haven't encountered any issues related to this. The app syncs with iCloud. Questions, preferable for anybody with knowledge of SwiftData internals: What will break in SwiftData when there are 2 duplicate numbers? Not that I would expect it to be safe, but does it happen to be safe to ship an update that changes V4's version to 1.3.0, what was originally intended?
0
0
168
Jul ’25
Reply to SwiftData changes made in widget via AppIntent are not reflected in main app until full relaunch
In SwiftData, there are local changes and remote changes. Local changes are made from the same model container (ModelContainer); remote changes are made from a different model container. This is covered in the WWDC25 session: SwiftData: Dive into inheritance and schema migration (starting at 13:54). Your main app and its widget use different model containers (because they run in a different process). For your main app, a change made from your widget is remote, and isn't observable. If a view in your main app observes a SwiftData model, or a result set that you fetch from a SwiftData store, it won't get updated for any remote change. If you use @Query, however, the query controller under the hood observes the remote changes, and so a query-back SwiftUI view is supposed to get updated for a remote change. This is clearly described in the mentioned WWDC25 session. If you see otherwise, I’d suggest that you file a feedback report with a reproducible case, and share you
Jul ’25
Request Analytics Reports via POST Call
Hi everyone! When I attempt the Post Request using Postman, as shown in my attached curl, I receive the error { errors: [ { status: 405, code: METHOD_NOT_ALLOWED, title: The request method is not valid for the resource path., detail: The request method used for this request is not valid for the resource path. Please consult the documentation. } ] }. I have constructed the JWT correctly as an admin with correct private Key and Unix Times and I am able to send regular GET requests without issue and I can view the dashboards in App Store Connect. The described POST request is being rejected, although it says so in the documentation: https://developer.apple.com/documentation/appstoreconnectapi/post-v1-analyticsreportrequests. Curl: curl --location 'https://api.appstoreconnect.apple.com/v1/analyticsReportRequests' --header 'Content-Type: application/json' --header 'Authorization: Bearer XXX' --data '{ data: { type: analyticsReportRequests, attributes: { accessType: ONGOING }, relationships: { app: { data:
3
0
506
Jul ’25
Inconsistent appTransactionId in Transaction History
Issue Description When using the App Store Server API endpoint GET v2/history/{transactionId} to retrieve transaction history for a specific transaction, I'm observing unexpected changes in the appTransactionId field across related transactions in the same subscription group. Important Context: This is a clean auto-renewable subscription with no user intervention - the user has had continuous auto-renewals without any upgrades, downgrades, cancellations, or resubscriptions. The subscription has been renewing automatically and successfully throughout the entire period. API Call GET v2/history/1000000000000001 Response Data The API returns the following transaction history, where I notice the appTransactionId values are inconsistent across what should be a straightforward auto-renewal sequence: Note: The data below has been sanitized for privacy protection (IDs, bundle identifiers, etc. have been replaced with example values), but the logical relationships, date sequences, and the core issue remain ide
2
0
180
Jul ’25
Reply to SwiftData and 'Circular references'
Don't mind me, just necro'ing an old thread. I'm running into this issue as well, and followed the same advice of omit the @Relationship macro from the child item and (of course) it resolves the compiler errors, but is this manual setting of the parent relationship intended? It's clearly not the best developer experience.
Jul ’25
Reply to WWDC25 Metal & game technologies group lab
If Getting into visionOS and metal for creating games - Is there any tips or optimal apis/framework/tools that you would recommend? Easiest way to start on visionOS is with RealityKit. The GameController framework supports lots of controllers for different types of games. 200GB of Background Assets available for content rich games. Are there standard methods of achieving synchronization of state between players (specifically using VisionOS here) or is it a roll-your-own situation? For synchronizing objects in a Shared spatial environment, consider using TableTopKit, which is compatible with GKMatch in the GameKit framework. If you’re using RealityKit, you can use SynchronizationService to coordinate shared physically simulated objects. We also recommend the WWDC session: Share visionOS experiences with nearby people. Which official Metal docs or sample projects best support teams moving a CPU-centric CAD kernel to GPU-accelerated workflows on Apple Silicon The Performing Calculations on a GPU sample code show
Topic: Graphics & Games SubTopic: Metal Tags:
Jul ’25
SwiftData changes made in widget via AppIntent are not reflected in main app until full relaunch
Hi, I’m using SwiftData with an @Observable DatabaseManager class that is shared between my app and a widget. This class is located inside a Swift package and looks roughly like this: public final class DatabaseManager { public static let shared = DatabaseManager() private init() { let groupID = group.com.yourcompany.myApp let config = ModelConfiguration(groupContainer: .identifier(groupID)) let c = try! ModelContainer(for: MyModel.self, configurations: config) self.container = c self.modelContext = c.mainContext } public private(set) var container: ModelContainer public private(set) var modelContext: ModelContext } In the main app, I inject the container and context like this: struct MyApp: App { var body: some Scene { WindowGroup { ContentView() .modelContainer(DatabaseManager.shared.container) .modelContext(DatabaseManager.shared.modelContext) } } } Both the widget and the main app import the same package, and both use DatabaseManager.shared for reading and writing objects. The problem: When the w
2
0
319
Jul ’25
Can you Clear Unwanted Version/Build History?
I have been developing an app for some time and tried distributing it via TestFlight to a couple of close friends but was getting crashes. It was an odd SwiftData Predicate thing that only showed up on TestFlight builds and not on builds downloaded from Xcode. Bottom line is I have created a whole bunch of unwanted version numbers thinking (incorrectly) that I needed to advance both the version number and the build number when uploading. The App has never been released so actually not even version 1.0 and I had created a bunch of versions all the way up to 1.11 before I realized my error. Now I am using a version 0.9 and just increasing the build number as I iterate thru external beta versions. The problem I have now is that TestFlight is still offering the version 1.11 build as the latest version to testers and I need to tell them how to ignore that go to the App in TestFlight and navigate to the Previous Builds under version 0.9 and download the latest build from there (this is tedious and confusin
0
0
201
Jul ’25
App crashed when switching between Annotation Tab and Group Tab with TabView init(selection:content:)
This app will not crash when switching between these two tabs with TabView init(content:) import SwiftUI import SwiftData struct ContentView: View { @StateObject private var highlightManager = HighlightManager.shared @State private var selectedTab: Int = 0 var body: some View { TabView(selection: $selectedTab) { MapView() .tabItem { Label(Map, systemImage: map) } .tag(0) // Annotation Tab AnnotationList() .tabItem { Label(Annotation, systemImage: mappin.and.ellipse) } .tag(1) // Group Tab PeopleList() .tabItem { Label(Group, systemImage: person.and.person) } .tag(2) } .tutorialOverlay() // Apply the overlay to the root view .environmentObject(highlightManager) .toolbar { ToolbarItem(placement: .confirmationAction) { NavigationLink(Help) { NavigationStack { HelpView(selectedTab: selectedTab) } } } } } }
2
0
138
Jul ’25
Reply to What is going on with transformable
@Jerome_Donfack There are two main requirements to use transformer in SwiftData: The type returned by transformedValueClass needs to correspond to the type you declare in the model, so it needs to be changed to NSArray.self transformedValue can only be encoded as NSData, and in CoreData, we can encode into any supported type, such as NSNumber, NSString Override class func transformedValueClass() -> AnyClass { Return NSArray.self // change to NSArray } BTW: If it is not to be compatible with your other custom data, SwiftData will use the built-in transaformer to encode [String] without using transformable
Jul ’25
Reply to Modifying an associated value of an existing enum instance
Thank you @DTS Engineer , this is what the rest of the enum cases, and its computed properties, look like: enum FilterItem: Hashable { case work(isSelected: Bool) case family(isSelected: Bool) case health(isSelected: Bool) case social(isSelected: Bool) case energetic(isSelected: Bool) case tired(isSelected: Bool) case restless(isSelected: Bool) case heavy(isSelected: Bool) case numb(isSelected: Bool) case calm(isSelected: Bool) case tense(isSelected: Bool) case light(isSelected: Bool) case racing(isSelected: Bool) case focused(isSelected: Bool) case confused(isSelected: Bool) case overthinking(isSelected: Bool) case blank(isSelected: Bool) case reflective(isSelected: Bool) case head(isSelected: Bool) case neck(isSelected: Bool) case chest(isSelected: Bool) case shoulders(isSelected: Bool) case arms(isSelected: Bool) case solarPlexus(isSelected: Bool) case stomach(isSelected: Bool) case lowerAbdomen(isSelected: Bool) case legs(isSelected: Bool) case wholeBody(isSelected: Bool) var filterName: String { switch s
Replies
Boosts
Views
Activity
Jul ’25
SwiftData Background Fetching?
Hi, I am experiencing main thread freezes from fetching on Main Actor. Attempting to move the function to a background thread, but whenever I reference the TestModel in a nonisolated context or in another model actor, I get this warning: Main actor-isolated conformance of 'TestModel' to 'PersistentModel' cannot be used in actor-isolated context; this is an error in the Swift 6 language mode Is there a way to do this correctly? Recreation, warning on line 13: class TestModel { var property: Bool = true init() {} } struct SendableTestModel: Sendable { let property: Bool } @ModelActor actor BackgroundActor { func fetch() throws -> [SendableTestModel] { try modelContext.fetch(FetchDescriptor()).map { SendableTestModel(property: $0.property) } } }
Replies
1
Boosts
0
Views
145
Activity
Jul ’25
Reply to SwiftData Class Inheritance
Check out the talk for SwiftData to get some insight on when you should harness Class Inheritance: https://developer.apple.com/videos/play/wwdc2025/291/ As for the depth and width of your Model Graph, it really depends on the full Schema and how the data is partitioned for the particular use cases.
Replies
Boosts
Views
Activity
Jul ’25
SwiftData Class Inheritance
Hi, I'm considering using the new SwiftData class inheritance for a new app I'm building. I have a few questions: Is it working well enough for production? I have a number of different object types in my app. Some of them are very similar, and there's always a balance to be struck when it comes to splitting them into different types using class inheritance. Are there some good advice on when to use multiple classes instead of squeezing my object types into a single class? Is there advice against using class inheritance in multiple levels (3-4)? Claes
Replies
1
Boosts
0
Views
134
Activity
Jul ’25
Consequences of incorrect VersionedSchema.versionIdentifier
About 4 months ago, I shipped the first version of my app with 4 versioned schemas that, unintentionally, had the same versionIdentifier of 1.2.0 in 2 of them: V1: 1.0.0 V2: 1.1.0 V3: 1.2.0 V4: 1.2.0 They are ordered correctly in the MigrationPlan, and they are all lightweight. Migration works, SwiftData doesn't crash on init and I haven't encountered any issues related to this. The app syncs with iCloud. Questions, preferable for anybody with knowledge of SwiftData internals: What will break in SwiftData when there are 2 duplicate numbers? Not that I would expect it to be safe, but does it happen to be safe to ship an update that changes V4's version to 1.3.0, what was originally intended?
Replies
0
Boosts
0
Views
168
Activity
Jul ’25
Reply to SwiftData changes made in widget via AppIntent are not reflected in main app until full relaunch
In SwiftData, there are local changes and remote changes. Local changes are made from the same model container (ModelContainer); remote changes are made from a different model container. This is covered in the WWDC25 session: SwiftData: Dive into inheritance and schema migration (starting at 13:54). Your main app and its widget use different model containers (because they run in a different process). For your main app, a change made from your widget is remote, and isn't observable. If a view in your main app observes a SwiftData model, or a result set that you fetch from a SwiftData store, it won't get updated for any remote change. If you use @Query, however, the query controller under the hood observes the remote changes, and so a query-back SwiftUI view is supposed to get updated for a remote change. This is clearly described in the mentioned WWDC25 session. If you see otherwise, I’d suggest that you file a feedback report with a reproducible case, and share you
Replies
Boosts
Views
Activity
Jul ’25
Request Analytics Reports via POST Call
Hi everyone! When I attempt the Post Request using Postman, as shown in my attached curl, I receive the error { errors: [ { status: 405, code: METHOD_NOT_ALLOWED, title: The request method is not valid for the resource path., detail: The request method used for this request is not valid for the resource path. Please consult the documentation. } ] }. I have constructed the JWT correctly as an admin with correct private Key and Unix Times and I am able to send regular GET requests without issue and I can view the dashboards in App Store Connect. The described POST request is being rejected, although it says so in the documentation: https://developer.apple.com/documentation/appstoreconnectapi/post-v1-analyticsreportrequests. Curl: curl --location 'https://api.appstoreconnect.apple.com/v1/analyticsReportRequests' --header 'Content-Type: application/json' --header 'Authorization: Bearer XXX' --data '{ data: { type: analyticsReportRequests, attributes: { accessType: ONGOING }, relationships: { app: { data:
Replies
3
Boosts
0
Views
506
Activity
Jul ’25
Reply to How to listen for QUIC connections using the new NetworkListener in iOS 26?
For the moment I recommend that you hold on on trying to use QUIC with the new Network framework API that we introduced at WWDC 2025. The relationship between that API and multiplexed protocols is still evolving. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = eskimo + 1 + @ + apple.com
Replies
Boosts
Views
Activity
Jul ’25
Inconsistent appTransactionId in Transaction History
Issue Description When using the App Store Server API endpoint GET v2/history/{transactionId} to retrieve transaction history for a specific transaction, I'm observing unexpected changes in the appTransactionId field across related transactions in the same subscription group. Important Context: This is a clean auto-renewable subscription with no user intervention - the user has had continuous auto-renewals without any upgrades, downgrades, cancellations, or resubscriptions. The subscription has been renewing automatically and successfully throughout the entire period. API Call GET v2/history/1000000000000001 Response Data The API returns the following transaction history, where I notice the appTransactionId values are inconsistent across what should be a straightforward auto-renewal sequence: Note: The data below has been sanitized for privacy protection (IDs, bundle identifiers, etc. have been replaced with example values), but the logical relationships, date sequences, and the core issue remain ide
Replies
2
Boosts
0
Views
180
Activity
Jul ’25
Reply to SwiftData and 'Circular references'
Don't mind me, just necro'ing an old thread. I'm running into this issue as well, and followed the same advice of omit the @Relationship macro from the child item and (of course) it resolves the compiler errors, but is this manual setting of the parent relationship intended? It's clearly not the best developer experience.
Replies
Boosts
Views
Activity
Jul ’25
Reply to WWDC25 Metal & game technologies group lab
If Getting into visionOS and metal for creating games - Is there any tips or optimal apis/framework/tools that you would recommend? Easiest way to start on visionOS is with RealityKit. The GameController framework supports lots of controllers for different types of games. 200GB of Background Assets available for content rich games. Are there standard methods of achieving synchronization of state between players (specifically using VisionOS here) or is it a roll-your-own situation? For synchronizing objects in a Shared spatial environment, consider using TableTopKit, which is compatible with GKMatch in the GameKit framework. If you’re using RealityKit, you can use SynchronizationService to coordinate shared physically simulated objects. We also recommend the WWDC session: Share visionOS experiences with nearby people. Which official Metal docs or sample projects best support teams moving a CPU-centric CAD kernel to GPU-accelerated workflows on Apple Silicon The Performing Calculations on a GPU sample code show
Topic: Graphics & Games SubTopic: Metal Tags:
Replies
Boosts
Views
Activity
Jul ’25
SwiftData changes made in widget via AppIntent are not reflected in main app until full relaunch
Hi, I’m using SwiftData with an @Observable DatabaseManager class that is shared between my app and a widget. This class is located inside a Swift package and looks roughly like this: public final class DatabaseManager { public static let shared = DatabaseManager() private init() { let groupID = group.com.yourcompany.myApp let config = ModelConfiguration(groupContainer: .identifier(groupID)) let c = try! ModelContainer(for: MyModel.self, configurations: config) self.container = c self.modelContext = c.mainContext } public private(set) var container: ModelContainer public private(set) var modelContext: ModelContext } In the main app, I inject the container and context like this: struct MyApp: App { var body: some Scene { WindowGroup { ContentView() .modelContainer(DatabaseManager.shared.container) .modelContext(DatabaseManager.shared.modelContext) } } } Both the widget and the main app import the same package, and both use DatabaseManager.shared for reading and writing objects. The problem: When the w
Replies
2
Boosts
0
Views
319
Activity
Jul ’25
Can you Clear Unwanted Version/Build History?
I have been developing an app for some time and tried distributing it via TestFlight to a couple of close friends but was getting crashes. It was an odd SwiftData Predicate thing that only showed up on TestFlight builds and not on builds downloaded from Xcode. Bottom line is I have created a whole bunch of unwanted version numbers thinking (incorrectly) that I needed to advance both the version number and the build number when uploading. The App has never been released so actually not even version 1.0 and I had created a bunch of versions all the way up to 1.11 before I realized my error. Now I am using a version 0.9 and just increasing the build number as I iterate thru external beta versions. The problem I have now is that TestFlight is still offering the version 1.11 build as the latest version to testers and I need to tell them how to ignore that go to the App in TestFlight and navigate to the Previous Builds under version 0.9 and download the latest build from there (this is tedious and confusin
Replies
0
Boosts
0
Views
201
Activity
Jul ’25
App crashed when switching between Annotation Tab and Group Tab with TabView init(selection:content:)
This app will not crash when switching between these two tabs with TabView init(content:) import SwiftUI import SwiftData struct ContentView: View { @StateObject private var highlightManager = HighlightManager.shared @State private var selectedTab: Int = 0 var body: some View { TabView(selection: $selectedTab) { MapView() .tabItem { Label(Map, systemImage: map) } .tag(0) // Annotation Tab AnnotationList() .tabItem { Label(Annotation, systemImage: mappin.and.ellipse) } .tag(1) // Group Tab PeopleList() .tabItem { Label(Group, systemImage: person.and.person) } .tag(2) } .tutorialOverlay() // Apply the overlay to the root view .environmentObject(highlightManager) .toolbar { ToolbarItem(placement: .confirmationAction) { NavigationLink(Help) { NavigationStack { HelpView(selectedTab: selectedTab) } } } } } }
Replies
2
Boosts
0
Views
138
Activity
Jul ’25
Reply to What is going on with transformable
@Jerome_Donfack There are two main requirements to use transformer in SwiftData: The type returned by transformedValueClass needs to correspond to the type you declare in the model, so it needs to be changed to NSArray.self transformedValue can only be encoded as NSData, and in CoreData, we can encode into any supported type, such as NSNumber, NSString Override class func transformedValueClass() -> AnyClass { Return NSArray.self // change to NSArray } BTW: If it is not to be compatible with your other custom data, SwiftData will use the built-in transaformer to encode [String] without using transformable
Replies
Boosts
Views
Activity
Jul ’25