Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

Cannot use Hypervisor with inherited app sandbox
I have a main app with the entitlements: com.apple.security.app-sandbox com.apple.security.hypervisor and a helper app with the entitlements com.apple.security.app-sandbox com.apple.security.inherit According to the documentations, if I start the helper app with NSTask, it should inherit the sandbox and I do see that for file accesses. However, when I try to use Hypervisor.framework, I get HV_DENIED. If I try to add com.apple.security.hypervisor to the helper app, then the NSTask spawned process crashes with Could not set sandbox profile data: Operation not permitted (1). I believe this is a bug and have submitted FB8921623 In the meantime, is there a workaround other than disabling App Sandbox or sticking to a single app (not possible for our application)?
1
0
909
Dec ’20
Re: Resolving App Sandbox Inheritance Problems
I have a werid case that shouldn't happen according to https://forums.developer.apple.com/forums/thread/706390 I have an audio unit which runs in FCP and I want it to launch a sandboxed app as a child process. If I sign the child app with just com.apple.security.app-sandbox entitlement it crashes with SYSCALL_SET_PROFILE error. According to the article referenced above: This indicates that the process tried to setup its sandbox profile but that failed, in this case because it already has a sandbox profile. This makes sense because audio units run in a sandboxed environment (in AUHostingService process). So I added com.apple.security.inherit to the entitlements plist and now I get Process is not in an inherited sandbox. error. According to the article referenced above: Another cause of a trap within _libsecinit_appsandbox is when a nonsandboxed process runs another program as a child process and that other program’s executable has the com.apple.security.app-sandbox and com.apple.security.inherit entit
3
0
912
Dec ’24
SwiftData how to release the relationship data after popping the view back
ViewA has ModelA ViewA loads into the memory. ModelA is queried and shown in the list. ModelA has an array of ModelB which is faulted for the memory. When you select an item in the list in ViewA ViewB is loaded and ModelB information is displayed. When you pop back to ViewA, ModelB is still in the memory since it is contained within the array of ModelA. how could i make this memory efficient by releasing ModelB from the memory. should I refetch everything? or is there another method?
1
0
499
Feb ’24
Question about the Scope and "Inheritance" Behavior of SwiftUI Modifiers
I am confused about the inheritance behavior of modifiers in SwiftUI. Some modifiers (such as .background, .clipShape, etc.) seem to affect both parent and child views inconsistently. Here are some specific examples I encountered in Xcode 16.4 with the iOS 18.5 iPhone 16 Pro simulator: struct ContentView: View { var body: some View { VStack { // RedVStack Text(Hello world!) VStack { // OrangeVStack Text(Hello) Text(Hello) } .background(.orange) } .background(.red, in: RoundedRectangle(cornerRadius: 5)) // RedVStack has rounded corners, OrangeVStack also has rounded corners } } struct ContentView: View { var body: some View { VStack { // RedVStack Text(Hello world!) VStack { // OrangeVStack Text(Hello) Text(Hello) } .background(.orange) Text(Hello world!) } .background(.red, in: RoundedRectangle(cornerRadius: 5)) // RedVStack has rounded corners, OrangeVStack does not have rounded corners } } struct ContentView: View { var body: some View { VStack { // RedVStack Text(Hello world!) VStack { // OrangeVS
0
0
88
Aug ’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
Reply to SwiftData Relationship Delete Not Working (SwiftData/PersistentModel.swift:359)
The issue should go away if you make the to-one relationships optional: @Model class Model2 { var name: String var model1: Model1? ... } @Model class Model3 { var name: String var model2: Model2? ... } To be clear, I understand that your intent is to express a non-optional to-one relationship with Swift, and yet it is a caveat that, when using SwiftData one-to-many relationship + cascade delete rule, you would want to make the to-one relationship optional. If using non-optional to-one relationship doesn't work for you, I'd suggest that you file a feedback report and share your report ID here. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’25
Reply to CloudKit - moving record objects between zones
If you are using SwiftData + CloudKit, which is based on NSPersistentCloudKitContainer, it doesn't support cross-share relationships, and so you can't have a collection in one zone and a relationship of the collection (a sub-collection, for example) in another. This is mentioned in here: NSPersistentCloudKitContainer doesn’t support cross-share relationships. That is, it doesn’t allow relating objects associated with different shares. When sharing an object, NSPersistentCloudKitContainer moves the entire object graph, which includes the object and all its relationships, to the share’s record zone. If you are using the CloudKit framework directly, the source and target objects of CKRecord.Reference must be in the same zone of the same database, and so you will need to maintain the relationship with your own logic. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: Community SubTopic: Apple Developers Tags:
Nov ’25
Reply to SwiftData initializing Optional Array to Empty Array
What you observed is the behavior that the framework currently has – If you save the model context right after adding a book, you will see that the relationship turns from nil to [] immediately, and that's because SwiftData makes the change when persisting the model. SwiftData does that because the default store (DefaultStore) is based on Core Data, and Core Data expresses an empty toMany relationship with an empty set. (Core Data had been implemented with Objective C long before Swift was introduced.) Having said that, if you have a different opinion about the behavior, feel free to file a feedback report – If you do so, please share your report ID here. Thanks. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Aug ’25
Reply to how can I discern which SwiftData object trigger the .NSManagedObjectContextDidSave notification ?
I don't see any good solution for iOS 17 unfortunately. Some folks discussed how to convert the permanent objectID of a Core Data managed object to a SwiftData PersistentIdentifier (and find the associated SwiftData model from there), but the relationship between NSManagedObjectID and PersistentIdentifier is not publicly documented, and so is not something I'd talk about. Another piece worth mentioning: I just confirmed that ModelContext.didSave now works on iOS 18 (22A3364). If you are using .NSManagedObjectContextDidSave, you can replace it with ModelContext.didSave and grab the SwiftData changes from the notification's user info dictionary. With that, you don't need to look into the SwiftData history. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Oct ’24
A crash occurs when fetching history when Model has preserveValueOnDeletion attribute and using inheritance
Hello, In our app, we’ve modeled our schema using inheritance introduced in iOS 26.0, and we’re implementing SwiftData History to re-fetch models only when necessary. @Model public class Transaction { @Attribute(.preserveValueOnDeletion) public var date: Date = Date() public var amount: Double = 0 public var memo: String? } @Model public final class Spending: Transaction { public var installmentIndex: Int = 1 public var installment: Int = 1 public var installmentID: UUID? } If data has been deleted from database, we need to check a date property to determine whether to re-fetch datas. To do this, we added the preserveValueOnDeletion attribute to date property so we could retrieve it from the History tombstone value. However, after adding this attribute, a crash occurs. There is a console log Could not cast value of type 'Swift.ReferenceWritableKeyPath' (0x106bf8328) to 'Swift.PartialKeyPath' (0x1094f21d8). and error log attached StrictMoneyChecking-2025-11-07-105108.txt I also tried this in
1
0
298
Nov ’25
SwiftData synced to iCloud with one-to-many relationship between 2 models results in a crash when each model contains a reference to the other
I’m having an issue when two of my SwiftData models have a one-to-many relationship and I have them synced via CloudKit. To be clear, I’ve met all of the requirements to make it iCloud friendly and sync to work. I followed this https://www.hackingwithswift.com/quick-start/swiftdata/how-to-sync-swiftdata-with-icloud, and can confirm I’ve done it correctly because initially I was seeing this crash on startup when I had not: Thread 1: Fatal error: Could not create ModelContainer: SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer) This is to say, the problem may be iCloud related but it’s not due to a wrong model setup. Speaking of which, these are models: @Model class Film { var name: String = var releaseYear: Int = 0 var director: Director? = nil init(name: String, releaseYear: Int, director: Director) { self.name = name self.releaseYear = releaseYear self.director = director } } @Model class Director { var name: String = @Relationship(
1
0
1.4k
Mar ’24
Protocol inheritance that heats up my computer
I've noticed that a seemingly insignificant modification of the program below will make the compiler work for ever at 99% cpu.This is the program without the modification (so it will compile normally):protocol Nat { static var intValue: Int { get } } protocol NonZero : Nat { typealias Pred : Nat } struct Zero : Nat { static var intValue: Int { return 0 } } struct Succ<P: Nat> : NonZero { typealias Pred = P static var intValue: Int { return P.intValue + 1 } } protocol StaticArrayType { typealias Element typealias Arity : Nat var startIndex: Int { get } var endIndex: Int { get } subscript (position: Int) -> Element { get } } extension StaticArrayType { var startIndex: Int { return 0 } var endIndex: Int { return Arity.intValue } } struct EmptyStaticArray<Element> : StaticArrayType, CollectionType { typealias Arity = Zero subscript (position: Int) -> Element { fatalError(Index out of bounds!) } } struct StaticArray<Tail: StaticArrayType> : StaticArrayType, CollectionType { typealias Arity
1
0
451
Sep ’15
Adding a Location Model class doesn't inherit from the root NSObject
I am new to xCode but learning.I am using this learning tool:https://codewithchris.com/iphone-app-connect-to-mysql-database/But it says to select folder and Add File, then it will inherest some properties in the code, but it inherits nothing.All I get is the UIKit code.Has there been a fundamental change in xcode, or have I not gone through the right options.When I did do Add File, there was an option of various Classes to choose from, not shown in their tutorial. I took the Cocoa one as it was default.Can someone please help?Simon
0
0
329
Dec ’17
Cannot use Hypervisor with inherited app sandbox
I have a main app with the entitlements: com.apple.security.app-sandbox com.apple.security.hypervisor and a helper app with the entitlements com.apple.security.app-sandbox com.apple.security.inherit According to the documentations, if I start the helper app with NSTask, it should inherit the sandbox and I do see that for file accesses. However, when I try to use Hypervisor.framework, I get HV_DENIED. If I try to add com.apple.security.hypervisor to the helper app, then the NSTask spawned process crashes with Could not set sandbox profile data: Operation not permitted (1). I believe this is a bug and have submitted FB8921623 In the meantime, is there a workaround other than disabling App Sandbox or sticking to a single app (not possible for our application)?
Replies
1
Boosts
0
Views
909
Activity
Dec ’20
Re: Resolving App Sandbox Inheritance Problems
I have a werid case that shouldn't happen according to https://forums.developer.apple.com/forums/thread/706390 I have an audio unit which runs in FCP and I want it to launch a sandboxed app as a child process. If I sign the child app with just com.apple.security.app-sandbox entitlement it crashes with SYSCALL_SET_PROFILE error. According to the article referenced above: This indicates that the process tried to setup its sandbox profile but that failed, in this case because it already has a sandbox profile. This makes sense because audio units run in a sandboxed environment (in AUHostingService process). So I added com.apple.security.inherit to the entitlements plist and now I get Process is not in an inherited sandbox. error. According to the article referenced above: Another cause of a trap within _libsecinit_appsandbox is when a nonsandboxed process runs another program as a child process and that other program’s executable has the com.apple.security.app-sandbox and com.apple.security.inherit entit
Replies
3
Boosts
0
Views
912
Activity
Dec ’24
SwiftData how to release the relationship data after popping the view back
ViewA has ModelA ViewA loads into the memory. ModelA is queried and shown in the list. ModelA has an array of ModelB which is faulted for the memory. When you select an item in the list in ViewA ViewB is loaded and ModelB information is displayed. When you pop back to ViewA, ModelB is still in the memory since it is contained within the array of ModelA. how could i make this memory efficient by releasing ModelB from the memory. should I refetch everything? or is there another method?
Replies
1
Boosts
0
Views
499
Activity
Feb ’24
Question about the Scope and "Inheritance" Behavior of SwiftUI Modifiers
I am confused about the inheritance behavior of modifiers in SwiftUI. Some modifiers (such as .background, .clipShape, etc.) seem to affect both parent and child views inconsistently. Here are some specific examples I encountered in Xcode 16.4 with the iOS 18.5 iPhone 16 Pro simulator: struct ContentView: View { var body: some View { VStack { // RedVStack Text(Hello world!) VStack { // OrangeVStack Text(Hello) Text(Hello) } .background(.orange) } .background(.red, in: RoundedRectangle(cornerRadius: 5)) // RedVStack has rounded corners, OrangeVStack also has rounded corners } } struct ContentView: View { var body: some View { VStack { // RedVStack Text(Hello world!) VStack { // OrangeVStack Text(Hello) Text(Hello) } .background(.orange) Text(Hello world!) } .background(.red, in: RoundedRectangle(cornerRadius: 5)) // RedVStack has rounded corners, OrangeVStack does not have rounded corners } } struct ContentView: View { var body: some View { VStack { // RedVStack Text(Hello world!) VStack { // OrangeVS
Replies
0
Boosts
0
Views
88
Activity
Aug ’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
Reply to SwiftData Relationship Delete Not Working (SwiftData/PersistentModel.swift:359)
The issue should go away if you make the to-one relationships optional: @Model class Model2 { var name: String var model1: Model1? ... } @Model class Model3 { var name: String var model2: Model2? ... } To be clear, I understand that your intent is to express a non-optional to-one relationship with Swift, and yet it is a caveat that, when using SwiftData one-to-many relationship + cascade delete rule, you would want to make the to-one relationship optional. If using non-optional to-one relationship doesn't work for you, I'd suggest that you file a feedback report and share your report ID here. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Jan ’25
Reply to CloudKit - moving record objects between zones
If you are using SwiftData + CloudKit, which is based on NSPersistentCloudKitContainer, it doesn't support cross-share relationships, and so you can't have a collection in one zone and a relationship of the collection (a sub-collection, for example) in another. This is mentioned in here: NSPersistentCloudKitContainer doesn’t support cross-share relationships. That is, it doesn’t allow relating objects associated with different shares. When sharing an object, NSPersistentCloudKitContainer moves the entire object graph, which includes the object and all its relationships, to the share’s record zone. If you are using the CloudKit framework directly, the source and target objects of CKRecord.Reference must be in the same zone of the same database, and so you will need to maintain the relationship with your own logic. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: Community SubTopic: Apple Developers Tags:
Replies
Boosts
Views
Activity
Nov ’25
Reply to SwiftData Many to One Cascade Delete not working as I expect in Xcode15 Beta 7 & 8
Try to delete var recipe: Recipe? = nil and inverse: FoodMenu.recipe, it should be fixed. Unlike CoreData, SwiftData simplifies the declarations. Just need to add var menus: [FoodMenu]? with @Relationship(deleteRule: .cascade).
Replies
Boosts
Views
Activity
Mar ’24
Reply to SwiftData initializing Optional Array to Empty Array
What you observed is the behavior that the framework currently has – If you save the model context right after adding a book, you will see that the relationship turns from nil to [] immediately, and that's because SwiftData makes the change when persisting the model. SwiftData does that because the default store (DefaultStore) is based on Core Data, and Core Data expresses an empty toMany relationship with an empty set. (Core Data had been implemented with Objective C long before Swift was introduced.) Having said that, if you have a different opinion about the behavior, feel free to file a feedback report – If you do so, please share your report ID here. Thanks. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Aug ’25
Reply to Added new field to swiftdata model, now crashes
Same issue today. Xcode 15.4 iOS 17.4 & 17.5. Submitted feedback FB13812722 (Complex Migrations with SwiftData do not work. Irrelevant Error: Fatal error: Expected only Arrays for Relationships - String)
Replies
Boosts
Views
Activity
May ’24
Reply to how can I discern which SwiftData object trigger the .NSManagedObjectContextDidSave notification ?
I don't see any good solution for iOS 17 unfortunately. Some folks discussed how to convert the permanent objectID of a Core Data managed object to a SwiftData PersistentIdentifier (and find the associated SwiftData model from there), but the relationship between NSManagedObjectID and PersistentIdentifier is not publicly documented, and so is not something I'd talk about. Another piece worth mentioning: I just confirmed that ModelContext.didSave now works on iOS 18 (22A3364). If you are using .NSManagedObjectContextDidSave, you can replace it with ModelContext.didSave and grab the SwiftData changes from the notification's user info dictionary. With that, you don't need to look into the SwiftData history. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Oct ’24
A crash occurs when fetching history when Model has preserveValueOnDeletion attribute and using inheritance
Hello, In our app, we’ve modeled our schema using inheritance introduced in iOS 26.0, and we’re implementing SwiftData History to re-fetch models only when necessary. @Model public class Transaction { @Attribute(.preserveValueOnDeletion) public var date: Date = Date() public var amount: Double = 0 public var memo: String? } @Model public final class Spending: Transaction { public var installmentIndex: Int = 1 public var installment: Int = 1 public var installmentID: UUID? } If data has been deleted from database, we need to check a date property to determine whether to re-fetch datas. To do this, we added the preserveValueOnDeletion attribute to date property so we could retrieve it from the History tombstone value. However, after adding this attribute, a crash occurs. There is a console log Could not cast value of type 'Swift.ReferenceWritableKeyPath' (0x106bf8328) to 'Swift.PartialKeyPath' (0x1094f21d8). and error log attached StrictMoneyChecking-2025-11-07-105108.txt I also tried this in
Replies
1
Boosts
0
Views
298
Activity
Nov ’25
SwiftData synced to iCloud with one-to-many relationship between 2 models results in a crash when each model contains a reference to the other
I’m having an issue when two of my SwiftData models have a one-to-many relationship and I have them synced via CloudKit. To be clear, I’ve met all of the requirements to make it iCloud friendly and sync to work. I followed this https://www.hackingwithswift.com/quick-start/swiftdata/how-to-sync-swiftdata-with-icloud, and can confirm I’ve done it correctly because initially I was seeing this crash on startup when I had not: Thread 1: Fatal error: Could not create ModelContainer: SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer) This is to say, the problem may be iCloud related but it’s not due to a wrong model setup. Speaking of which, these are models: @Model class Film { var name: String = var releaseYear: Int = 0 var director: Director? = nil init(name: String, releaseYear: Int, director: Director) { self.name = name self.releaseYear = releaseYear self.director = director } } @Model class Director { var name: String = @Relationship(
Replies
1
Boosts
0
Views
1.4k
Activity
Mar ’24
Protocol inheritance that heats up my computer
I've noticed that a seemingly insignificant modification of the program below will make the compiler work for ever at 99% cpu.This is the program without the modification (so it will compile normally):protocol Nat { static var intValue: Int { get } } protocol NonZero : Nat { typealias Pred : Nat } struct Zero : Nat { static var intValue: Int { return 0 } } struct Succ<P: Nat> : NonZero { typealias Pred = P static var intValue: Int { return P.intValue + 1 } } protocol StaticArrayType { typealias Element typealias Arity : Nat var startIndex: Int { get } var endIndex: Int { get } subscript (position: Int) -> Element { get } } extension StaticArrayType { var startIndex: Int { return 0 } var endIndex: Int { return Arity.intValue } } struct EmptyStaticArray<Element> : StaticArrayType, CollectionType { typealias Arity = Zero subscript (position: Int) -> Element { fatalError(Index out of bounds!) } } struct StaticArray<Tail: StaticArrayType> : StaticArrayType, CollectionType { typealias Arity
Replies
1
Boosts
0
Views
451
Activity
Sep ’15
Adding a Location Model class doesn't inherit from the root NSObject
I am new to xCode but learning.I am using this learning tool:https://codewithchris.com/iphone-app-connect-to-mysql-database/But it says to select folder and Add File, then it will inherest some properties in the code, but it inherits nothing.All I get is the UIKit code.Has there been a fundamental change in xcode, or have I not gone through the right options.When I did do Add File, there was an option of various Classes to choose from, not shown in their tutorial. I took the Cocoa one as it was default.Can someone please help?Simon
Replies
0
Boosts
0
Views
329
Activity
Dec ’17