I had the impression that when encoding with a key, I could set any undefined attribute to NSManagedObject at run time, and no exception would be thrown, but that would be a way to hold objects attached to a model that are not in the data model.
For example, I have a Foo object that does not have the "bar" attribute. I, although this is at runtime, I could set it like this:
Foo *foo = [NSEntityDescription insertNewObjectForEntityForName:@"Foo" inManagedObjectContext:ManagedObjectContext];
[foo setValue:@"foobar" forUndefinedKey:@"bar"];
Then I expected that the ManagedObjectContext will keep this value until I request it later, but saving in a managed object context will not save the value of the string.
A famous bug keeps popping up when I run this code:
the entity Foo is not key value coding-compliant for the key "bar"
.. so my question is: what am I not getting or doing wrong?
source
share