|
@delawaremathguy in a response on UUID's in CoreData you said this: (3) i also use UUIDs to keep the Core Data model a little flatter and the Core Data store more lean. that is, rather than having relationships all throughout the object graph, it's sometimes sufficient in my case to record the UUID of one object B in another object A, instead of having a Core Data "one-to-many relationship pointer" from A to B. entity B no longer needs an NSSet? data type to record the inverse relationship. if i need to match up the appropriate B entity with A later, i can do a fetch for entities of B's type with their id: UUID matching A's UUID reference for B. Are you storing all id's as UUID? In other words are you storing the id from object B in Object A as a UUID or as a string? Do you have a snippet showing how you reference the "relationship" in Swift to get all Object B's belonging to an specific Object A that you can share? |
|
hi Michael, took a few minutes to remember this, but yes, i do have two active (but private) projects using some variant of this strategy. (1) i give every Core Data entity an attribute (2) just for the record, i may have gotten the language reversed about what was an A and what was a B. even i am confused as i look back (!) so let's be concrete:
so, how do you match these up?
it's an open question about whether this is the right thing to do. it comes down to a time-space tradeoff, perhaps; and there are ways to speed up the fetching ... e.g., keep a dictionary of golfers keyed by id, in which case but in one case i had, the Core Data object graph had some "almost circular" relationships among three entities ... and SwiftUI (in particular) seemed very unhappy about this. and in another case, i am using two separate Core Data stores (one a local configuration that stays on device, and a second that NSPersistentCloudKitContainer synchronizes across devices via CloudKit). there is no way to express a relationship between two Core Data entities that live in separate configurations other than to store the id of an object in one configuration into an object in the other configuration. hope that helps, and feel free to contact me -- i am on GitHub. DMG (added after the fact: it took me a little bit of time to locate a link to the discussion that initiated Michael's question.) |
|
DMG, Thanks, I had been doing something similar prior to SwiftUI, I called the golferId a "parentId". So every Entity has an "id" and a "parentId". I haven't yet woked out the SwiftUI code for the third level or belwo, but when I do, I'll post it back here. Think: Programs, Projects, Tasks, Sub-Tasks, and Notes at every level. |
|
hi Michael, for what you describe ... i think ... i think Core Data can handle this quite easily with one-to-many relationships from parent to child, and i doubt there's much to gain by going down the UUID route. Core Data is scalable; and sometimes you will appreciate having only to use a single line of code to delete a my concerns (not so well described months ago, i am afraid) did not involve such a simple hierarchy. honestly: unless there's a reason to use UUIDs and look-up code in place of using Core Data relationships, i'd avoid doing so. i'll look forward to seeing what you might post in the future. hope that helps, DMG |
SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.