Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

CoreData to-Many relationship saving NSSet relationship property
I have an ShoppingItem Entity(attributes: name, id, unit, qty, description) and another entity ShoppingList(attributes: listDate, listName) and a relationship property : items which is many-to-many relationship. The use case is : _The items that are selected by the user have to be updated to the list on the particular date. let myList = GroceryList(context: CoreDataManager.shared.viewContext) myList.name = One more List myList.madeOn = Date() 1. myList.mutableSetValue(forKey: groceryItems).add(selectedGroceryItems) CoreDataManager.shared.save() selectedGroceryItems is of type struct ItemEntityViewModel { let groceryItem: GroceryItem var itemEntityid: NSManagedObjectID { return groceryItem.objectID } var id: UUID { return groceryItem.id ?? UUID() } var name: String { return groceryItem.name ?? } var category: String { return groceryItem.category ?? Not available } var unit: String? { return groceryItem.unit ?? } var qty: Double? { return Double(groceryItem.qty) } } line 1 throws exception a
3
0
570
Oct ’21
SwiftData SortDescriptor Limitation...
I built a SwiftData App that relies on CloudKit to synchronize data across devices. That means all model relationships must be expressed as Optional. That’s fine, but there is a limitation in using Optional’s in SwiftData SortDescriptors (Crashes App) That means I can’t apply a SortDescriptor to ModelA using some property value in ModelB (even if ModelB must exist) I tried using a computed property in ModelA that referred to the property in ModelB, BUT THIS DOESN”T WORK EITHER! Am I stuck storing redundant data In ModelA just to sort ModelA as I would like???
4
0
192
Jul ’25
Index in Spotlight on an entity relationship
I'm implementing CoreSpotlight searching on my Core Data store. The Index in Spotlight checkbox appears in Xcode for Relationships but when I check it and then run a spotlight search it does not find my entity based on the relationship value. What am I missing? Is there more to the process? For example, if I have an entity of Event and another for Keyword with a relationship between them I would expect that checking Index on the relationship from Event to Keyword would return the event for Basketball Game if I searched for the keyword Sport.
0
0
803
Nov ’18
Reply to SwiftData: Unable to delete (Xcode 16)
I have the same issue, on iOS 18 and MacOS 15 I can't delete an item. My item has relationships. It's working on iOS 17.5. Also, I have the same issue when modifying an sub-item in my item. Here are the logs: Thread 0 name: Thread 0 Crashed: 0 libswiftCore.dylib 0x00000001946291a8 _assertionFailure(_:_:file:line:flags:) + 264 (AssertCommon.swift:147) 1 SwiftData 0x00000002524066a4 _FullFutureBackingData.getValue(forKey:) + 780 (BackingData.swift:494) 2 SwiftData 0x0000000252406cb4 protocol witness for BackingData.getValue(forKey:) in conformance _FullFutureBackingData + 24 (:0) 3 SwiftData 0x00000002523a579c onOptionalArray #1 (_:) in PersistentModel.remove(_:for:on:) + 316 (PersistentModel.swift:414) 4 SwiftData 0x00000002523a7340 specialized PersistentModel.withRelationship(from:to:by:onModel:onOptionalModel:onArray:onOptionalArray:onCodableArray:onOptionalCodableArray:) + 1060 (PersistentModel.swift:0) 5 SwiftData 0x00000002523a82d0 specialized Persiste
Jun ’24
Reply to Does SwiftData currently supports data sharing among multiple users through iCloud?
SwiftData + CloudKit integration doesn’t support CloudKit sharing as of today. I haven’t tried to implement SwiftData + CloudKit sharing with my own effort, but based on my understanding on the technologies, if the object graph to be shared is relatively complicated, I'd consider sticking with NSPersistentCloudKitContainer (Core Data), because NSPersistentCloudKitContainer interacts with Core Data, and using SwiftData adds another layer of complexity. If the data to be shared is quite simple, such as a small set of values without relationships, and I have built my app with SwiftData, I might consider using CloudKit API directly to implement the sharing flow. That way, I completely control the synchronization and sharing process, and can share any data type, including SwiftData. For the first option, you can start with the following sample: Sharing Core Data objects between iCloud users The second option may turn out a bit involved. You can start with the t
Oct ’24
When I inherit from a class assigning SceneLocationView() sceneNode is nil
When I try to post a LocationAnnotations of a subclass respect to the one defining variable sceneLocationView, by way of: sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: bannerAnnotationLocation) When I enter in: public func addLocationNodeWithConfirmedLocation(locationNode: LocationNode) { if locationNode.location == nil || locationNode.locationConfirmed == false { return } updatePositionAndScaleOfLocationNode(locationNode: locationNode, initialSetup: true, animated: true) locationNodes.append(locationNode) print(sceneNode?.description ?? nil) self.sceneNode?.addChildNode(locationNode) } I find sceneNode to nil, like if the effect of the renderer is lost when subclassing. I also tried to create a new variable in the subclass also assigning SceneLocationView(), but sceneNode remains nil. What to do to force it to assume a value?
1
0
74
May ’25
Advantages Of SwiftData
What sets the SwiftData framework apart from traditional iOS data storage solutions like Core Data or Realm? Could you elaborate on SwiftData's unique features and architecture that enable developers to efficiently manage data in their Swift projects? How does SwiftData enhance the development experience by seamlessly integrating with Swift's language features and paradigms
3
0
884
Apr ’24
Batch Update for Relationships
Hi All, I am importing a huge chunk of data from our SQL Server to our iPads for our sales reps to have archived data when they are in areas without cell service. I can bring in the data via JSON with ease. The problem I am running into is how to create the relationship between two entities efficiently as there are thousands of records. For example, I have two entities: Order and OrderLine Order has a one-to-many relationship with OrderLine called lines. OrderLine has the inverse called order. Both entities have a common key called orderKey. Using For loops on the Order entity and then filtering the OrderLine and adding them to the Order is way too slow. I am hoping that there is a way to do a batch update on the relationship or what would be the best way to match up the data in the two entities. I'm using Swift 5.5 Thanks in advance!
0
0
497
May ’23
Complex Swift Data Relationships...
I am struggling with exactly how to set up SwiftData relationships, beyond the single relationship model... Let's say I have a school. Each school offers a set of classes. Each class is taught by one teacher and attended by several students. Teachers may teach more than one class, but only at one school. Similarly students may attend more than one class, but only at one school. Classes themselves may be offered at more than one school. Can someone create a class for School, SchoolClass, Teacher, and Student with id, name, and relationships... I have tried it unsuccessfully about 10 different ways at this point. My most recent is below... I am struggling getting beyond a school listing in the app, and I'll cross that bridge next. I am just wondering if all the trouble I am having is because I am not smart with the class definitions. And wondering if this is to complex for SwiftData and CoreData is the requirement. This is not a real app, just my way of really trying
Topic: Design SubTopic: General Tags:
6
0
790
Jun ’25
CloudKit don't sync Relationships
CloudKit + Core Data I created two entities Credit Card Relationship: transactions Transaction Relationship: creditcard Configuration: Default is already set used with CloudKit Problem The relationships don't sync. For example, on 1st device. let creditCard = CreditCard(context: viewContext) creditCard.name = First Card let firstTransaction = CCTransaction(context: viewContext) firstTransaction.price = First Transaction firstTransaction.price = 100 creditCard.addToTransactions(firstTransaction) firstTransaction.creditcard = creditCard try! viewContext.save() // Check transactions print(creditCard.transactions.count) // 1 on 2nd device after synced @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: CreditCard.name, ascending: true)], animation: .default) var creditcards: FetchedResults // Check transactions ForEach(creditcards) { creditcard in Card() .onTapGesture { print(creditCard.transactions.count) // will have a value of 0 except the device that records the relationship
0
0
632
Nov ’21
one to many relationship
I am trying to get my head around a problem involving a one to many relationship. I'm not sure that my approach to this design is a good one.I have two entities, address and rooms. An address can have many rooms. I have set up a one to many relationship between the address table and room table. The problem is differentiating the Living Room of address 1 from the Living Room of address 2. Currently when I call NSManagedObject, the table rows are displaying all the rooms regardless of the address being chosen. I am not sure how to uniquely identify a room with an address.Sorry this is so vague, but I'm pretty new to core data, and I'm not even sure if my approach is a valid one. Any help to get me pointe in the right direction would be greatly appreciated.
2
0
349
Jun ’15
SwiftData .returnsDistinctResults ?
With NSFetchRequest of coreData it was possible to only return distinct results from the database with .returnsDistinctResults What if any is the fetch equivalent in SwiftData ? currently I'm appending entries into a Set. Only with over 200k rows and no newBackgroundContext() in SwiftData the UI is locked for a number of seconds
1
0
823
Oct ’23
CoreData to-Many relationship saving NSSet relationship property
I have an ShoppingItem Entity(attributes: name, id, unit, qty, description) and another entity ShoppingList(attributes: listDate, listName) and a relationship property : items which is many-to-many relationship. The use case is : _The items that are selected by the user have to be updated to the list on the particular date. let myList = GroceryList(context: CoreDataManager.shared.viewContext) myList.name = One more List myList.madeOn = Date() 1. myList.mutableSetValue(forKey: groceryItems).add(selectedGroceryItems) CoreDataManager.shared.save() selectedGroceryItems is of type struct ItemEntityViewModel { let groceryItem: GroceryItem var itemEntityid: NSManagedObjectID { return groceryItem.objectID } var id: UUID { return groceryItem.id ?? UUID() } var name: String { return groceryItem.name ?? } var category: String { return groceryItem.category ?? Not available } var unit: String? { return groceryItem.unit ?? } var qty: Double? { return Double(groceryItem.qty) } } line 1 throws exception a
Replies
3
Boosts
0
Views
570
Activity
Oct ’21
SwiftData SortDescriptor Limitation...
I built a SwiftData App that relies on CloudKit to synchronize data across devices. That means all model relationships must be expressed as Optional. That’s fine, but there is a limitation in using Optional’s in SwiftData SortDescriptors (Crashes App) That means I can’t apply a SortDescriptor to ModelA using some property value in ModelB (even if ModelB must exist) I tried using a computed property in ModelA that referred to the property in ModelB, BUT THIS DOESN”T WORK EITHER! Am I stuck storing redundant data In ModelA just to sort ModelA as I would like???
Replies
4
Boosts
0
Views
192
Activity
Jul ’25
Index in Spotlight on an entity relationship
I'm implementing CoreSpotlight searching on my Core Data store. The Index in Spotlight checkbox appears in Xcode for Relationships but when I check it and then run a spotlight search it does not find my entity based on the relationship value. What am I missing? Is there more to the process? For example, if I have an entity of Event and another for Keyword with a relationship between them I would expect that checking Index on the relationship from Event to Keyword would return the event for Basketball Game if I searched for the keyword Sport.
Replies
0
Boosts
0
Views
803
Activity
Nov ’18
to-many relationship fault "..." for objectID
I have a one-many relationship between A and B, when add B to A' set, I got the debug log to-many relationship fault for objectID. How to deal with it?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
0
Boosts
0
Views
136
Activity
Jun ’15
Reply to SwiftData: Unable to delete (Xcode 16)
I have the same issue, on iOS 18 and MacOS 15 I can't delete an item. My item has relationships. It's working on iOS 17.5. Also, I have the same issue when modifying an sub-item in my item. Here are the logs: Thread 0 name: Thread 0 Crashed: 0 libswiftCore.dylib 0x00000001946291a8 _assertionFailure(_:_:file:line:flags:) + 264 (AssertCommon.swift:147) 1 SwiftData 0x00000002524066a4 _FullFutureBackingData.getValue(forKey:) + 780 (BackingData.swift:494) 2 SwiftData 0x0000000252406cb4 protocol witness for BackingData.getValue(forKey:) in conformance _FullFutureBackingData + 24 (:0) 3 SwiftData 0x00000002523a579c onOptionalArray #1 (_:) in PersistentModel.remove(_:for:on:) + 316 (PersistentModel.swift:414) 4 SwiftData 0x00000002523a7340 specialized PersistentModel.withRelationship(from:to:by:onModel:onOptionalModel:onArray:onOptionalArray:onCodableArray:onOptionalCodableArray:) + 1060 (PersistentModel.swift:0) 5 SwiftData 0x00000002523a82d0 specialized Persiste
Replies
Boosts
Views
Activity
Jun ’24
Reply to Does SwiftData currently supports data sharing among multiple users through iCloud?
SwiftData + CloudKit integration doesn’t support CloudKit sharing as of today. I haven’t tried to implement SwiftData + CloudKit sharing with my own effort, but based on my understanding on the technologies, if the object graph to be shared is relatively complicated, I'd consider sticking with NSPersistentCloudKitContainer (Core Data), because NSPersistentCloudKitContainer interacts with Core Data, and using SwiftData adds another layer of complexity. If the data to be shared is quite simple, such as a small set of values without relationships, and I have built my app with SwiftData, I might consider using CloudKit API directly to implement the sharing flow. That way, I completely control the synchronization and sharing process, and can share any data type, including SwiftData. For the first option, you can start with the following sample: Sharing Core Data objects between iCloud users The second option may turn out a bit involved. You can start with the t
Replies
Boosts
Views
Activity
Oct ’24
When I inherit from a class assigning SceneLocationView() sceneNode is nil
When I try to post a LocationAnnotations of a subclass respect to the one defining variable sceneLocationView, by way of: sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: bannerAnnotationLocation) When I enter in: public func addLocationNodeWithConfirmedLocation(locationNode: LocationNode) { if locationNode.location == nil || locationNode.locationConfirmed == false { return } updatePositionAndScaleOfLocationNode(locationNode: locationNode, initialSetup: true, animated: true) locationNodes.append(locationNode) print(sceneNode?.description ?? nil) self.sceneNode?.addChildNode(locationNode) } I find sceneNode to nil, like if the effect of the renderer is lost when subclassing. I also tried to create a new variable in the subclass also assigning SceneLocationView(), but sceneNode remains nil. What to do to force it to assume a value?
Replies
1
Boosts
0
Views
74
Activity
May ’25
Advantages Of SwiftData
What sets the SwiftData framework apart from traditional iOS data storage solutions like Core Data or Realm? Could you elaborate on SwiftData's unique features and architecture that enable developers to efficiently manage data in their Swift projects? How does SwiftData enhance the development experience by seamlessly integrating with Swift's language features and paradigms
Replies
3
Boosts
0
Views
884
Activity
Apr ’24
Batch Update for Relationships
Hi All, I am importing a huge chunk of data from our SQL Server to our iPads for our sales reps to have archived data when they are in areas without cell service. I can bring in the data via JSON with ease. The problem I am running into is how to create the relationship between two entities efficiently as there are thousands of records. For example, I have two entities: Order and OrderLine Order has a one-to-many relationship with OrderLine called lines. OrderLine has the inverse called order. Both entities have a common key called orderKey. Using For loops on the Order entity and then filtering the OrderLine and adding them to the Order is way too slow. I am hoping that there is a way to do a batch update on the relationship or what would be the best way to match up the data in the two entities. I'm using Swift 5.5 Thanks in advance!
Replies
0
Boosts
0
Views
497
Activity
May ’23
SwiftData
Is there a way to view the data saved when using swiftdata? Even after deleting all models, the storage space taken up by the app in Settings is too large.
Replies
2
Boosts
0
Views
746
Activity
Apr ’24
Complex Swift Data Relationships...
I am struggling with exactly how to set up SwiftData relationships, beyond the single relationship model... Let's say I have a school. Each school offers a set of classes. Each class is taught by one teacher and attended by several students. Teachers may teach more than one class, but only at one school. Similarly students may attend more than one class, but only at one school. Classes themselves may be offered at more than one school. Can someone create a class for School, SchoolClass, Teacher, and Student with id, name, and relationships... I have tried it unsuccessfully about 10 different ways at this point. My most recent is below... I am struggling getting beyond a school listing in the app, and I'll cross that bridge next. I am just wondering if all the trouble I am having is because I am not smart with the class definitions. And wondering if this is to complex for SwiftData and CoreData is the requirement. This is not a real app, just my way of really trying
Topic: Design SubTopic: General Tags:
Replies
6
Boosts
0
Views
790
Activity
Jun ’25
CloudKit don't sync Relationships
CloudKit + Core Data I created two entities Credit Card Relationship: transactions Transaction Relationship: creditcard Configuration: Default is already set used with CloudKit Problem The relationships don't sync. For example, on 1st device. let creditCard = CreditCard(context: viewContext) creditCard.name = First Card let firstTransaction = CCTransaction(context: viewContext) firstTransaction.price = First Transaction firstTransaction.price = 100 creditCard.addToTransactions(firstTransaction) firstTransaction.creditcard = creditCard try! viewContext.save() // Check transactions print(creditCard.transactions.count) // 1 on 2nd device after synced @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: CreditCard.name, ascending: true)], animation: .default) var creditcards: FetchedResults // Check transactions ForEach(creditcards) { creditcard in Card() .onTapGesture { print(creditCard.transactions.count) // will have a value of 0 except the device that records the relationship
Replies
0
Boosts
0
Views
632
Activity
Nov ’21
one to many relationship
I am trying to get my head around a problem involving a one to many relationship. I'm not sure that my approach to this design is a good one.I have two entities, address and rooms. An address can have many rooms. I have set up a one to many relationship between the address table and room table. The problem is differentiating the Living Room of address 1 from the Living Room of address 2. Currently when I call NSManagedObject, the table rows are displaying all the rooms regardless of the address being chosen. I am not sure how to uniquely identify a room with an address.Sorry this is so vague, but I'm pretty new to core data, and I'm not even sure if my approach is a valid one. Any help to get me pointe in the right direction would be greatly appreciated.
Replies
2
Boosts
0
Views
349
Activity
Jun ’15
SwiftData .returnsDistinctResults ?
With NSFetchRequest of coreData it was possible to only return distinct results from the database with .returnsDistinctResults What if any is the fetch equivalent in SwiftData ? currently I'm appending entries into a Set. Only with over 200k rows and no newBackgroundContext() in SwiftData the UI is locked for a number of seconds
Replies
1
Boosts
0
Views
823
Activity
Oct ’23
NSBatchInsertRequest and 2 tables with one-to-relationship
hi everybody, I have a database in which there are 2 tables with a one-many relationship. I need to use NSBatchInsertRequest because I have a large data’s to insert in db. I know that NSBatchInsertRequest doesn’t manages relationships. so how can I use NSBatchInsertRequest to insert data and insert the relationships? thank you
Replies
0
Boosts
0
Views
811
Activity
Feb ’21