Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

Detecting When App Token Is Removed Due to Category Selection in FamilyActivityPicker
I'm working with the Screen Time API (FamilyActivityPicker) in SwiftUI and need help with a specific scenario. I'm using the FamilyActivityPicker to let users select apps and categories to block. I save the previous selection (both applicationTokens and categoryTokens) locally. When the user updates their selection, I compare the new selection with the saved one to determine which apps or categories were removed. However, I’m trying to handle a specific case: when an individual app token is removed from the selection because its entire category was selected instead. In this situation, even though the app is no longer in applicationTokens, it's still blocked due to its category being included in categoryTokens. Since I need to show users which apps were actually removed, I want to avoid listing apps that are still indirectly blocked via a selected category. I’ve created a mapping between ApplicationToken and FamilyActivityCategoryToken to check whether a removed app is still covered by a selected category befo
2
0
198
Jul ’25
Reply to Detecting When App Token Is Removed Due to Category Selection in FamilyActivityPicker
[quote='791334021, Nasheet, /thread/791334, /profile/Nasheet'] does the system not give access to the relationship between apps and their categories [/quote] This is not possible unfortunately. I desperately need the same functionality for my app as well. A while ago I sent a feedback request / radar to Apple but haven’t heard anything back: FB16121372 I would urge you to file a feedback request as well: Demonstrate your use-case. Showcase how this would not affect user-privacy (you still don‘t know which app and category are represented by each token, you just know that they’re related). Post your feedback number here as well 🙌 Let’s work on this together and shape the future of the Screen Time API – such an important topic nowadays that deserves more attention by Apple!
Topic: App & System Services SubTopic: General Tags:
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
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
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
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 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
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
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
Migrating Sign in with Apple users for an app transfer
Dear Apple Developer Technical Support, We are currently following the official Apple documentation “TN3159: Migrating Sign in with Apple users for an app transfer” to carry out a Sign in with Apple user migration after successfully transferring several apps to a new developer account. Here is a summary of our situation: Under the original Apple developer account, we had five apps using Sign in with Apple, grouped under a shared primary app using App Grouping. Recently, we transferred three of these apps to our new Apple developer account via App Store Connect. After the transfer, these three apps are no longer associated with the original primary App ID. We reconfigured individual Services IDs for each app in the new account and enabled Sign in with Apple for each. More than 24 hours have passed since the app transfer was completed. Now we are attempting to follow the migration process to restore user access via the user.migration flow. Specifically, we are using the following script to request an Apple acce
3
0
414
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
SwiftData and 'Circular references'
Using the 'Create SwiftData Code...' action in Xcode results in Model that have bi-directional relationships between many of my entities (which is correct - my Core Data model includes this). All of these Relationships are marked as invalid, however, with the following error: Circular reference resolving attached macro 'Relationship' Most ORM's, in my experience, have a way to mark one end of a bidirectional relationship as an 'owner'. Is there something similar available in SwiftData, or is this scenario handled in a different way? Or am I going to need to remove all of my bidirectional relationships?
10
0
6.8k
Oct ’23
Reply to Fetching data with relationships directly faults the relationships even when not accessed
The only way around it I've found is to create an intermediate 1:1 model that contains the 1:N relationship since SwiftData won't query 1:1 relationships by default.
Replies
Boosts
Views
Activity
Jul ’25
Detecting When App Token Is Removed Due to Category Selection in FamilyActivityPicker
I'm working with the Screen Time API (FamilyActivityPicker) in SwiftUI and need help with a specific scenario. I'm using the FamilyActivityPicker to let users select apps and categories to block. I save the previous selection (both applicationTokens and categoryTokens) locally. When the user updates their selection, I compare the new selection with the saved one to determine which apps or categories were removed. However, I’m trying to handle a specific case: when an individual app token is removed from the selection because its entire category was selected instead. In this situation, even though the app is no longer in applicationTokens, it's still blocked due to its category being included in categoryTokens. Since I need to show users which apps were actually removed, I want to avoid listing apps that are still indirectly blocked via a selected category. I’ve created a mapping between ApplicationToken and FamilyActivityCategoryToken to check whether a removed app is still covered by a selected category befo
Replies
2
Boosts
0
Views
198
Activity
Jul ’25
Reply to Detecting When App Token Is Removed Due to Category Selection in FamilyActivityPicker
[quote='791334021, Nasheet, /thread/791334, /profile/Nasheet'] does the system not give access to the relationship between apps and their categories [/quote] This is not possible unfortunately. I desperately need the same functionality for my app as well. A while ago I sent a feedback request / radar to Apple but haven’t heard anything back: FB16121372 I would urge you to file a feedback request as well: Demonstrate your use-case. Showcase how this would not affect user-privacy (you still don‘t know which app and category are represented by each token, you just know that they’re related). Post your feedback number here as well 🙌 Let’s work on this together and shape the future of the Screen Time API – such an important topic nowadays that deserves more attention by Apple!
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jul ’25
Reply to Fetching data with relationships directly faults the relationships even when not accessed
@DTS Engineer This is still an issue. For now we stopped using relationships. Instead we store IDs and load entities lazy when accessed.
Replies
Boosts
Views
Activity
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
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
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 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
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
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
Migrating Sign in with Apple users for an app transfer
Dear Apple Developer Technical Support, We are currently following the official Apple documentation “TN3159: Migrating Sign in with Apple users for an app transfer” to carry out a Sign in with Apple user migration after successfully transferring several apps to a new developer account. Here is a summary of our situation: Under the original Apple developer account, we had five apps using Sign in with Apple, grouped under a shared primary app using App Grouping. Recently, we transferred three of these apps to our new Apple developer account via App Store Connect. After the transfer, these three apps are no longer associated with the original primary App ID. We reconfigured individual Services IDs for each app in the new account and enabled Sign in with Apple for each. More than 24 hours have passed since the app transfer was completed. Now we are attempting to follow the migration process to restore user access via the user.migration flow. Specifically, we are using the following script to request an Apple acce
Replies
3
Boosts
0
Views
414
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
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
SwiftData and 'Circular references'
Using the 'Create SwiftData Code...' action in Xcode results in Model that have bi-directional relationships between many of my entities (which is correct - my Core Data model includes this). All of these Relationships are marked as invalid, however, with the following error: Circular reference resolving attached macro 'Relationship' Most ORM's, in my experience, have a way to mark one end of a bidirectional relationship as an 'owner'. Is there something similar available in SwiftData, or is this scenario handled in a different way? Or am I going to need to remove all of my bidirectional relationships?
Replies
10
Boosts
0
Views
6.8k
Activity
Oct ’23