Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

Core Data concurrency to Swift and Relationship
The example used in the video is an update of the project used last year to explain the batch functions. in that project NSBatchInsertRequest is used to insert large data in few seconds but NSBatchInsertRequest could not be used to set the relationships. I don't understand if this is changed or not, but, if not, can I use the concurrency to set the relationship? is it possible to have an simple example in which you can save large data with relationship in few seconds?
0
0
907
Jun ’21
CoreData Codable Relationships
I have the following data model in CoreData:The relationships childs and parent are between objects of the same Type (Subject).Subject+CoreDataClass.swiftimport Foundation import CoreData @objc(Subject) public class Subject: NSManagedObject { }Subject+CoreDataPropertiesimport Foundation import CoreData extension Subject { @nonobjc public class func fetchRequest() -> NSFetchRequest<Subject> { return NSFetchRequest<Subject>(entityName: Subject) } @NSManaged public var idauto: NSNumber? @NSManaged public var longdescription: String? @NSManaged public var parentid: NSNumber? @NSManaged public var shortdescription: String? @NSManaged public var title: String? @NSManaged public var childs: NSSet? @NSManaged public var parent: Subject? }I would like to return a Json file from the content of the sqlite database, so I make the Subject class conform to Codable protocol as follow:Subject+CoreDataClass.swiftimport Foundation import CoreData @objc(Subject) public class Subject: NSManagedObject, Cod
3
0
7.6k
Feb ’18
Core Data and Relationships
I've a large data feed to load in database. this data populate many entities that are related each others. I've follow this official tutorial - https://developer.apple.com/documentation/coredata/loading_and_displaying_a_large_data_feed to use nsbatchInsertRequest. But this tutorial has one big bug: populate data only in one entity. How many apps use a database with only one entity? therefore the problem that I have not only me, but several people, is time. With nsbatchinsertrequst I was able to insert more than 30000 records in just 5 seconds with a use of just 25MB of RAM. But without setting up relationships. if after the execution of the various insertrequests I set the relations, everything takes me about 50 seconds with an increase in memory to 60-70 MB. Is it possible that there is no way to quickly set up relationships? Not only that, this is a forum where Apple engineers, who therefore know the subject better, should give help. but who knows why, for such questions they disappear. Ma
3
0
1.8k
Feb ’21
Reply to After upgrading to XCode 16 app stopped working
User should be able to filter CaliberData by specifying size range. #Predicate { caliberData in caliberData.sizeHeights.contains { sizeObject in sizeObject.id >= minSizeHeight && sizeObject.id <= maxSizeHeight } } You are right, that Float is actual size value, but had to wrap it into a custom class as a workaround due to some SwiftData limitation regarding using filtering predicates on value (or relationships (or both)). So using the actual value as 'id' to make it conform to needed Identifiable protocol made sense to save some space.
Oct ’24
How to subclass with SwiftData?
Hi, I want to subclass my model. Here is my superclass: import SwiftData @Model public class Control { @Attribute(.unique) public var frame: Frame init(frame: Frame) { self.frame = frame } } Here is my subclass: import SwiftData import CoreGraphics class SliderControl: Control { let axis: Axis var value: CGFloat = 0.0 init(axis: Axis, frame: Frame) { self.axis = axis super.init(frame: frame) } required public init(backingData: any BackingData, fromFetch: Bool = false) { // How to get `axis` and `value` from the backing data? } } I'm not sure how to use the backing data to re-create my object. My goal is to have multiple controls with unique properties.
5
0
4.9k
Jun ’23
swiftdata model polymorphism?
I have a SwiftData model where I need to customize behavior based on the value of a property (connectorType). Here’s a simplified version of my model: @Model public final class ConnectorModel { public var connectorType: String ... func doSomethingDifferentForEveryConnectorType() { ... } } I’d like to implement doSomethingDifferentForEveryConnectorType in a way that allows the behavior to vary depending on connectorType, and I want to follow best practices for scalability and maintainability. I’ve come up with three potential solutions, each with pros and cons, and I’d love to hear your thoughts on which one makes the most sense or if there’s a better approach: **Option 1: Use switch Statements ** func doSomethingDifferentForEveryConnectorType() { switch connectorType { case HTTP: // HTTP-specific logic case WebSocket: // WebSocket-specific logic default: // Fallback logic } } Pros: Simple to implement and keeps the SwiftData model observable by SwiftUI without any additional wrapping. Cons:
0
0
507
Jan ’25
UIAlertViewController tint color inherited from main window
Hi Guys,I am having some trouble setting the UIApperance property for UIAlertController. I am trying to change the color for Cancel Button but the following code does not work.[[UICollectionViewCell appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]];Has someone faced a similar issue ? its specific to iOS9ThanksAkhilesh
1
0
673
Sep ’15
Do child view controllers inherit the frame of their parents?
Below is my code. I have the ViewController, which takes up entire screen (set background color, makes sure status bar is visible, etc. It then calls up the MainController, which is set to be only in the safeAreaLayout frame. It has a button that brings up a third view controller when clicked. Everything works, the ViewController covers the entire screen, the MainController rests within the safeAreaLayouts of the iPhone X, and the third view controller comes up the same size and position as the MainController. It's that last part I want to make sure of, that that is the way it is supposed to come up. Can I count on that? Or must I set its frame myself to be sure? ViewController class ViewController: UIViewController { var mainController = MainController() override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() self.addChild(mainController) self.view.addSubview(mainController.view) setConstraints(vc: mainController, pc: view) } override func viewDidLoad() { super.viewDidLoad() view.backgroundColo
2
0
1.4k
Nov ’21
NSSavePanel not has the User Selected File Read/Write permission in a sandbox inherit child process
I have an application running in the sandbox which launches an application bundle using NSTask. The main app entitlements enable sandbox add the User Selected File Read/Write permission. com.apple.security.app-sandbox com.apple.security.files.user-selected.read-write The child app entitlements enable sandbox and inherit. com.apple.security.app-sandbox com.apple.security.inherit When invoke NSSavePanel *savePanel = [NSSavePanel savePanel] in the child process, system will throw the error.The error message prompt that missing the User Selected File Read/Write permission. However, I have already added this permission in the main app, and I have set up the inherit in the child-process as well. The child process cannot add the User Selected File Read/Write permission again because it add sandbox and inherit in entitlements by the doc EnablingAppSandbox . It appears that the system is not inheriting this permission for the child process. panel[60195:2499353] [OpenSavePane
1
0
952
Aug ’23
@Relationship crash on ios17.5 but not on ios18
In my app, I worked with ios18 by default and I had no issue, everything was working fine. However, when I wanted to test it with an iOS 17.5 simulator or real device, it is unusable because it crash when object with a relationship are created. on the first line you can see my relationship, and under it it is the extended relationship macro unmodifiable. has someone already encountered this? any clue of a hide modification of relationship working behavior in ios18? this is really annoying cause it make me unable to reduce the minimum deployment target of my app to ios17
4
0
1.2k
Sep ’24
Reply to SwiftData - Context missing for optional
I was running into this error when trying to delete an object from SwiftData when using an actual device on iOS 18 beta but not on a simulator running iOS 17. My model did have a @Relationship property attached to it as well. I added the following code when inserting an object and haven't gotten this crash the 10+ times I tried. Not idea if it's just a random coincidence or a work around for some bug. do { try modelContext.save() } catch { print(error) }
Jul ’24
Core Data concurrency to Swift and Relationship
The example used in the video is an update of the project used last year to explain the batch functions. in that project NSBatchInsertRequest is used to insert large data in few seconds but NSBatchInsertRequest could not be used to set the relationships. I don't understand if this is changed or not, but, if not, can I use the concurrency to set the relationship? is it possible to have an simple example in which you can save large data with relationship in few seconds?
Replies
0
Boosts
0
Views
907
Activity
Jun ’21
CoreData Codable Relationships
I have the following data model in CoreData:The relationships childs and parent are between objects of the same Type (Subject).Subject+CoreDataClass.swiftimport Foundation import CoreData @objc(Subject) public class Subject: NSManagedObject { }Subject+CoreDataPropertiesimport Foundation import CoreData extension Subject { @nonobjc public class func fetchRequest() -> NSFetchRequest<Subject> { return NSFetchRequest<Subject>(entityName: Subject) } @NSManaged public var idauto: NSNumber? @NSManaged public var longdescription: String? @NSManaged public var parentid: NSNumber? @NSManaged public var shortdescription: String? @NSManaged public var title: String? @NSManaged public var childs: NSSet? @NSManaged public var parent: Subject? }I would like to return a Json file from the content of the sqlite database, so I make the Subject class conform to Codable protocol as follow:Subject+CoreDataClass.swiftimport Foundation import CoreData @objc(Subject) public class Subject: NSManagedObject, Cod
Replies
3
Boosts
0
Views
7.6k
Activity
Feb ’18
Core Data and Relationships
I've a large data feed to load in database. this data populate many entities that are related each others. I've follow this official tutorial - https://developer.apple.com/documentation/coredata/loading_and_displaying_a_large_data_feed to use nsbatchInsertRequest. But this tutorial has one big bug: populate data only in one entity. How many apps use a database with only one entity? therefore the problem that I have not only me, but several people, is time. With nsbatchinsertrequst I was able to insert more than 30000 records in just 5 seconds with a use of just 25MB of RAM. But without setting up relationships. if after the execution of the various insertrequests I set the relations, everything takes me about 50 seconds with an increase in memory to 60-70 MB. Is it possible that there is no way to quickly set up relationships? Not only that, this is a forum where Apple engineers, who therefore know the subject better, should give help. but who knows why, for such questions they disappear. Ma
Replies
3
Boosts
0
Views
1.8k
Activity
Feb ’21
Reply to After upgrading to XCode 16 app stopped working
User should be able to filter CaliberData by specifying size range. #Predicate { caliberData in caliberData.sizeHeights.contains { sizeObject in sizeObject.id >= minSizeHeight && sizeObject.id <= maxSizeHeight } } You are right, that Float is actual size value, but had to wrap it into a custom class as a workaround due to some SwiftData limitation regarding using filtering predicates on value (or relationships (or both)). So using the actual value as 'id' to make it conform to needed Identifiable protocol made sense to save some space.
Replies
Boosts
Views
Activity
Oct ’24
SwiftData Testing
Hello everyone, I looked at various methods how to Unit/UITest SwiftData but I couldn't find something simple. Is it even possible to test SwiftData? Does someone found a solution for that?
Replies
0
Boosts
0
Views
771
Activity
May ’24
CloudKit JS and Many-To-Many relationships
Hi, I'm having difficulties fetching many 2 many relationships. I have an Actor entity (which I can query in CloudKit JS) that has 2 relationships: inputComponents and outputComponents, both pointing towards a Component entity. How to query these relationships? Thanks Tom
Replies
2
Boosts
0
Views
1.3k
Activity
3w
Why are ordered to-many relationships generated as OrderedSet?
When you use the Create NSMangledObject subclass feature in In Xcode 8 and Swift 3, any ordered to-many relationships are generated as OrderedSet. They should be NSMutableOrderedSet, as was handled properly by mogenerator.Apple: Please explain. Surely we need to be able to modify those relationships without being forced to make wholesale changes.
Replies
4
Boosts
0
Views
439
Activity
Jul ’16
How to subclass with SwiftData?
Hi, I want to subclass my model. Here is my superclass: import SwiftData @Model public class Control { @Attribute(.unique) public var frame: Frame init(frame: Frame) { self.frame = frame } } Here is my subclass: import SwiftData import CoreGraphics class SliderControl: Control { let axis: Axis var value: CGFloat = 0.0 init(axis: Axis, frame: Frame) { self.axis = axis super.init(frame: frame) } required public init(backingData: any BackingData, fromFetch: Bool = false) { // How to get `axis` and `value` from the backing data? } } I'm not sure how to use the backing data to re-create my object. My goal is to have multiple controls with unique properties.
Replies
5
Boosts
0
Views
4.9k
Activity
Jun ’23
swiftdata model polymorphism?
I have a SwiftData model where I need to customize behavior based on the value of a property (connectorType). Here’s a simplified version of my model: @Model public final class ConnectorModel { public var connectorType: String ... func doSomethingDifferentForEveryConnectorType() { ... } } I’d like to implement doSomethingDifferentForEveryConnectorType in a way that allows the behavior to vary depending on connectorType, and I want to follow best practices for scalability and maintainability. I’ve come up with three potential solutions, each with pros and cons, and I’d love to hear your thoughts on which one makes the most sense or if there’s a better approach: **Option 1: Use switch Statements ** func doSomethingDifferentForEveryConnectorType() { switch connectorType { case HTTP: // HTTP-specific logic case WebSocket: // WebSocket-specific logic default: // Fallback logic } } Pros: Simple to implement and keeps the SwiftData model observable by SwiftUI without any additional wrapping. Cons:
Replies
0
Boosts
0
Views
507
Activity
Jan ’25
UIAlertViewController tint color inherited from main window
Hi Guys,I am having some trouble setting the UIApperance property for UIAlertController. I am trying to change the color for Cancel Button but the following code does not work.[[UICollectionViewCell appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]];Has someone faced a similar issue ? its specific to iOS9ThanksAkhilesh
Replies
1
Boosts
0
Views
673
Activity
Sep ’15
Do child view controllers inherit the frame of their parents?
Below is my code. I have the ViewController, which takes up entire screen (set background color, makes sure status bar is visible, etc. It then calls up the MainController, which is set to be only in the safeAreaLayout frame. It has a button that brings up a third view controller when clicked. Everything works, the ViewController covers the entire screen, the MainController rests within the safeAreaLayouts of the iPhone X, and the third view controller comes up the same size and position as the MainController. It's that last part I want to make sure of, that that is the way it is supposed to come up. Can I count on that? Or must I set its frame myself to be sure? ViewController class ViewController: UIViewController { var mainController = MainController() override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() self.addChild(mainController) self.view.addSubview(mainController.view) setConstraints(vc: mainController, pc: view) } override func viewDidLoad() { super.viewDidLoad() view.backgroundColo
Replies
2
Boosts
0
Views
1.4k
Activity
Nov ’21
NSSavePanel not has the User Selected File Read/Write permission in a sandbox inherit child process
I have an application running in the sandbox which launches an application bundle using NSTask. The main app entitlements enable sandbox add the User Selected File Read/Write permission. com.apple.security.app-sandbox com.apple.security.files.user-selected.read-write The child app entitlements enable sandbox and inherit. com.apple.security.app-sandbox com.apple.security.inherit When invoke NSSavePanel *savePanel = [NSSavePanel savePanel] in the child process, system will throw the error.The error message prompt that missing the User Selected File Read/Write permission. However, I have already added this permission in the main app, and I have set up the inherit in the child-process as well. The child process cannot add the User Selected File Read/Write permission again because it add sandbox and inherit in entitlements by the doc EnablingAppSandbox . It appears that the system is not inheriting this permission for the child process. panel[60195:2499353] [OpenSavePane
Replies
1
Boosts
0
Views
952
Activity
Aug ’23
how to set relationship value of managedObject in NSBatchInsertRequest
setting managedObject's relationship value will occur error like 'Illegal attempt to establish a relationship ‘u’ser between objects in different contexts in NSBatchInsertRequest
Replies
1
Boosts
0
Views
1.1k
Activity
Mar ’21
@Relationship crash on ios17.5 but not on ios18
In my app, I worked with ios18 by default and I had no issue, everything was working fine. However, when I wanted to test it with an iOS 17.5 simulator or real device, it is unusable because it crash when object with a relationship are created. on the first line you can see my relationship, and under it it is the extended relationship macro unmodifiable. has someone already encountered this? any clue of a hide modification of relationship working behavior in ios18? this is really annoying cause it make me unable to reduce the minimum deployment target of my app to ios17
Replies
4
Boosts
0
Views
1.2k
Activity
Sep ’24
Reply to SwiftData - Context missing for optional
I was running into this error when trying to delete an object from SwiftData when using an actual device on iOS 18 beta but not on a simulator running iOS 17. My model did have a @Relationship property attached to it as well. I added the following code when inserting an object and haven't gotten this crash the 10+ times I tried. Not idea if it's just a random coincidence or a work around for some bug. do { try modelContext.save() } catch { print(error) }
Replies
Boosts
Views
Activity
Jul ’24