Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

SFAuthorizationPluginView's inherited controls remain on screen after successful login.
Our team is working on an Authorization Plugin that includes a UI as well, thus it works by creating a subclass of SFAuthorizationPluginView. Some of our users have reported that controls remain on the screen for a period of time even after a successful login. As shown in the attached screenshot, the native, inherited controls are the ones that remain on the screen, our plugin's controls disappear immediately. What I did to investigate this issue further, is that I checked the very basic Apple-provided example (modified by the community to bypass its issues): https://github.com/antoinebell/NameAndPassword Our users reported the exact same behavior once more. Inherited native controls (the back, forward buttons, the bottom 3 buttons ) all remained on the screen for a significant amount of time, even after the PluginDestroy and MechanismDestroy functions have been called. I would like to get confirmation on whether this is indeed an Apple-side issue or if anyone else have met this problem. I a
4
0
1.1k
Jan ’23
Creating custom synchronization primitives with priority inheritance
The Rust programming language is currently trying to replace its synchronization primitives with more efficient, statically initializable ones (see tracking issue). This turned out to be difficult on macOS, as it does neither have these primitives by default like Windows (SRWLock is really efficient and works with condition variables) or have a ready-to-use futex operation like Linux, FreeBSD, etc. A suitable alternative would be to use a parking lot like WebKit did, but that would make it impossible to implement priority-inheriting mutexes, which are somewhat important on an interactive system like macOS with its QoS feature. It turns out however, that macOS actually has a futex-like syscall called ulock_wait/ulock_wake. This syscall, while exposed through libSystem, is unfortunately private and its use has resulted in Apps being rejected from the App Store, which is unacceptable for a standard library like std. Since it is implemented since macOS 10.12, retroactively stabilizing the API would make
1
0
711
Jun ’22
Class inheritance not working in Archive builds?
I'm totally stumped. I have a new Swift project that embeds my own Swift framework, which has a bunch of base classes for view controllers, etc.I can build and run my local builds just fine. But when I Archive and upload to TestFlight, any build that gets installed fails to run as expected.A few overridden methods for key pieces of my app suddenly fail to get called, as if the normal inheritance chain is broken.For example, in a BaseViewController class, a viewDidLoad() method calls a localize() method.Then I subclass that view controller and override its viewDidLoad() and localize() methods, and make them call super before doing some custom work.In local builds, the subclass's viewDidLoad() and localize() methods get called as expected.But in archived builds, the subclass's localize() method never gets called.Even if I call localize() or self.localize() explicitly from the subclass, only the base class's version of localize() gets called.This is rather embarrassing because when I deploy a build to T
1
0
628
Feb ’17
Reply to How to handle required @relationship optionals in SwiftData CloudKit?
Sorry for not being clear. As an example, assuming you have some SwiftUI views that render the relationship, and the views accept only an non-optional array, it will make sense that your SwiftData model creates a computed property to wrap relationship. Here, the Swift views are the other part of your app that prefers to consume a non-optional array. I hope this makes the point clear. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Oct ’25
Reply to Swiftdata + Cloudkit + Mac OS how to configure for existing Swift Data store
One thing to mention is that the CloudKit integration requires that the SwiftData models follow some rules. For example, relationships must be optional, and unique constraints are not supported. I am wondering if it is that your SwiftData models don't follow the rules, which triggers the failure. The following documentation provides more information in that regard: Create a Data Model Best, —— Ziqiao Chen  Worldwide Developer Relations.
Oct ’24
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
Jun ’23
class method inheritance problem with swift
So, I've had this problem with swift since day 01. I've mentioned it a few times in these forums,a nd I haven't been able to get a satisfactory answer.there's a lot of details, but it resolves to this:a subclass, that overrides a superclass's method, never gets that overridden method called. Instead... The base class's method gets called.earlier in the day, the subclass's method would be called just after launch of the debug, but following something I haven't tied down yet, the base class's method gets called.So I have a base class : BKControlPropsit's got this method :open func mouseDraggedBehavior(event : NSEvent, viewPt : CGPoint){}now there is a successive list of subclasses:BKControlProps BKScrollerProps BKGroupProps BKListPropsScrollerProps overrides that mouseDraggedBehavior method:open override func mouseDraggedBehavior(event : NSEvent, viewPt : CGPoint){ let minOffset : CGFloat = 0.0025 switch scrollValue { case .none: break case .horiz: deltaAggregate += 2 / self.xWorkingLength * event.deltaX if abs
2
0
769
Oct ’18
Reply to Xcode 16.0. SwiftData Schema Fatal error: Inverse already set to another relationship
Xcode 16 reporting the error is a correct behavior to me, because in SwiftData, a relationship and its inverse must be a one to one pair. You code tries to set AccountModel.accountTransactions as the inverse relationship of both firstAccount and secondAccount, which is unsupported. You can consider consolidate firstAccount and secondAccount to something like accounts: [AccountModel]?, which makes it a many-to-many relationship. Thay way, a transaction model won't be constrained to have only two accounts, but should be good enough for your use case. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Sep ’24
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
Reply to SwiftData on iOS 18 extreme memory use
Thanks Ziqiao, for these great ideas! I've tried both, separately, in my test project.... Replacing the data property with a relationship does indeed avoid loading the images until needed. A good workaround. I'll test it in my real project to see what happens with more complexity and scale. Using fetchCount on a FetchDesciptor instead of count on SwiftData's Query array also improves things. It does not load the entire dataset to make the count. So thanks for these workarounds. Used together they may allow a SwiftData app to run normally on iOS 18. Now just thinking out loud, for myself and for fellow developers facing the same issues, strategizing about iOS 18 (and other fall 2024 os's).... Changing the image properties to relationships has these costs and risks.... I'll probably have to write a migrator, as this change seems unlikely to be handled automatically by lightweight migration. Will swift data reliably manage and discard the related items? Any different behavior
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’24
Reply to SwiftData crash when using a @Query sort descriptor with a relationship
Running into similar issue here. Adding error from console so other devs can find this when searching. SwiftData/Schema.swift:305: Fatal error: KeyPath Caliber.. points to a field () that is unknown to Caliber and cannot be used. From my investigation sort descriptor pointing to a relationship on a model is to blame (doesn't have to be @Query property wrapper, also used in FetchDescriptor crashes). Possible workaround - copy property from relationship to model and sort by it.
Feb ’25
SFAuthorizationPluginView's inherited controls remain on screen after successful login.
Our team is working on an Authorization Plugin that includes a UI as well, thus it works by creating a subclass of SFAuthorizationPluginView. Some of our users have reported that controls remain on the screen for a period of time even after a successful login. As shown in the attached screenshot, the native, inherited controls are the ones that remain on the screen, our plugin's controls disappear immediately. What I did to investigate this issue further, is that I checked the very basic Apple-provided example (modified by the community to bypass its issues): https://github.com/antoinebell/NameAndPassword Our users reported the exact same behavior once more. Inherited native controls (the back, forward buttons, the bottom 3 buttons ) all remained on the screen for a significant amount of time, even after the PluginDestroy and MechanismDestroy functions have been called. I would like to get confirmation on whether this is indeed an Apple-side issue or if anyone else have met this problem. I a
Replies
4
Boosts
0
Views
1.1k
Activity
Jan ’23
Creating custom synchronization primitives with priority inheritance
The Rust programming language is currently trying to replace its synchronization primitives with more efficient, statically initializable ones (see tracking issue). This turned out to be difficult on macOS, as it does neither have these primitives by default like Windows (SRWLock is really efficient and works with condition variables) or have a ready-to-use futex operation like Linux, FreeBSD, etc. A suitable alternative would be to use a parking lot like WebKit did, but that would make it impossible to implement priority-inheriting mutexes, which are somewhat important on an interactive system like macOS with its QoS feature. It turns out however, that macOS actually has a futex-like syscall called ulock_wait/ulock_wake. This syscall, while exposed through libSystem, is unfortunately private and its use has resulted in Apps being rejected from the App Store, which is unacceptable for a standard library like std. Since it is implemented since macOS 10.12, retroactively stabilizing the API would make
Replies
1
Boosts
0
Views
711
Activity
Jun ’22
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
Class inheritance not working in Archive builds?
I'm totally stumped. I have a new Swift project that embeds my own Swift framework, which has a bunch of base classes for view controllers, etc.I can build and run my local builds just fine. But when I Archive and upload to TestFlight, any build that gets installed fails to run as expected.A few overridden methods for key pieces of my app suddenly fail to get called, as if the normal inheritance chain is broken.For example, in a BaseViewController class, a viewDidLoad() method calls a localize() method.Then I subclass that view controller and override its viewDidLoad() and localize() methods, and make them call super before doing some custom work.In local builds, the subclass's viewDidLoad() and localize() methods get called as expected.But in archived builds, the subclass's localize() method never gets called.Even if I call localize() or self.localize() explicitly from the subclass, only the base class's version of localize() gets called.This is rather embarrassing because when I deploy a build to T
Replies
1
Boosts
0
Views
628
Activity
Feb ’17
Reply to How to handle required @relationship optionals in SwiftData CloudKit?
Sorry for not being clear. As an example, assuming you have some SwiftUI views that render the relationship, and the views accept only an non-optional array, it will make sense that your SwiftData model creates a computed property to wrap relationship. Here, the Swift views are the other part of your app that prefers to consume a non-optional array. I hope this makes the point clear. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Oct ’25
What does `Inherit from Target` option in Custom Class panel in Xcode 8.3 do?
I see that in Xcode 8.3 in the Custom Class Inspector, there is a new option `Inherit from Target` and I'm not sure what does it do? I haven't seen any mention of this in the release note niether?Here's a screenshot
Replies
2
Boosts
0
Views
10k
Activity
Apr ’17
Reply to Swiftdata + Cloudkit + Mac OS how to configure for existing Swift Data store
One thing to mention is that the CloudKit integration requires that the SwiftData models follow some rules. For example, relationships must be optional, and unique constraints are not supported. I am wondering if it is that your SwiftData models don't follow the rules, which triggers the failure. The following documentation provides more information in that regard: Create a Data Model Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Oct ’24
Reply to Inheritance in SwiftData — Fatal error: Never access a full future backing data
This looks like a known issue related to SwiftData failing to materialize a relationship that has a super class. I’d suggest that you file a feedback report so you can use it to request the latest status of the issue. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Sep ’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
Jun ’23
class method inheritance problem with swift
So, I've had this problem with swift since day 01. I've mentioned it a few times in these forums,a nd I haven't been able to get a satisfactory answer.there's a lot of details, but it resolves to this:a subclass, that overrides a superclass's method, never gets that overridden method called. Instead... The base class's method gets called.earlier in the day, the subclass's method would be called just after launch of the debug, but following something I haven't tied down yet, the base class's method gets called.So I have a base class : BKControlPropsit's got this method :open func mouseDraggedBehavior(event : NSEvent, viewPt : CGPoint){}now there is a successive list of subclasses:BKControlProps BKScrollerProps BKGroupProps BKListPropsScrollerProps overrides that mouseDraggedBehavior method:open override func mouseDraggedBehavior(event : NSEvent, viewPt : CGPoint){ let minOffset : CGFloat = 0.0025 switch scrollValue { case .none: break case .horiz: deltaAggregate += 2 / self.xWorkingLength * event.deltaX if abs
Replies
2
Boosts
0
Views
769
Activity
Oct ’18
Reply to Xcode 16.0. SwiftData Schema Fatal error: Inverse already set to another relationship
Xcode 16 reporting the error is a correct behavior to me, because in SwiftData, a relationship and its inverse must be a one to one pair. You code tries to set AccountModel.accountTransactions as the inverse relationship of both firstAccount and secondAccount, which is unsupported. You can consider consolidate firstAccount and secondAccount to something like accounts: [AccountModel]?, which makes it a many-to-many relationship. Thay way, a transaction model won't be constrained to have only two accounts, but should be good enough for your use case. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Sep ’24
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
Reply to SwiftData on iOS 18 extreme memory use
Thanks Ziqiao, for these great ideas! I've tried both, separately, in my test project.... Replacing the data property with a relationship does indeed avoid loading the images until needed. A good workaround. I'll test it in my real project to see what happens with more complexity and scale. Using fetchCount on a FetchDesciptor instead of count on SwiftData's Query array also improves things. It does not load the entire dataset to make the count. So thanks for these workarounds. Used together they may allow a SwiftData app to run normally on iOS 18. Now just thinking out loud, for myself and for fellow developers facing the same issues, strategizing about iOS 18 (and other fall 2024 os's).... Changing the image properties to relationships has these costs and risks.... I'll probably have to write a migrator, as this change seems unlikely to be handled automatically by lightweight migration. Will swift data reliably manage and discard the related items? Any different behavior
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’24
Reply to SwiftData crash when using a @Query sort descriptor with a relationship
Running into similar issue here. Adding error from console so other devs can find this when searching. SwiftData/Schema.swift:305: Fatal error: KeyPath Caliber.. points to a field () that is unknown to Caliber and cannot be used. From my investigation sort descriptor pointing to a relationship on a model is to blame (doesn't have to be @Query property wrapper, also used in FetchDescriptor crashes). Possible workaround - copy property from relationship to model and sort by it.
Replies
Boosts
Views
Activity
Feb ’25
Class B inherit Class A that adopt ObservableObject, @Published do not work?
Hi, guys. if I declared Class B inherit Class A that adopt ObservableObject, Class B has a @Published property, SwiftUI View not updating when the viewModel’s value changes? Is that a bug or something else?
Replies
1
Boosts
0
Views
689
Activity
Mar ’21