Quirk I just discovered, and wanted to confirm with anyone here whether or not this is avoidable. Basically, if I have a very simple two entity model:
With a to-many relationship between Entity1
and Entity2
. The relationship is optional, with nullify as the delete rule on both sides. However, if I insert a new Entity1
the value of the children
relationship will be an empty set, not nil
:
NSManagedObject *object = [NSEntityDescription
insertNewObjectForEntityForName:@"Entity1"
inManagedObjectContext:[self managedObjectContext]];
assert([object valueForKey:@"children"] != nil);
Furthermore, I can't explicitly set the relationship to nil
:
[object setValue:nil forKey:@"children"];
assert([object valueForKey:@"children"] != nil);
I have verified this in a new, minimal project and this appears to be a true implementation detail. The problem is, I would like to be able to differentiate between a nil
value (representing currently unknown) and an empty set (truly a to-zero relationship). Does CoreData actually support this at all in a reasonably direct manner? Currently it seems not, which means I will have to find another (less direct) way to represent my model.
Thanks,
J
Inverse relationships enable Core Data to propagate change in both directions when an instance of either the source or destination type changes. Every relationship must have an inverse. When creating relationships in the Graph editor, you add inverse relationships between entities in a single step.
Persistent storage has become an essential part of the majority of iOS apps nowadays. Core Data is a persistence and/or in-memory cache framework that consists of a very powerful set of other tools that can be used within the app.
Short answer is no. You will always get an empty set back. If you need to know if an object structure is fully realized (my guess at what your goal is) then you would want to set an attribute on the object to say if it is fully realized or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With