I have a NSManagedObject with a NSMutableArray as attribute:
@interface MyObject : NSManagedObject
{
}
@property (nonatomic, retain) id a1;
In the data model it is declared as Transformable
. I left the Value Transformer field like it is with the default (in light grey) NSKeyedUnarchiveFromData
.
a1 is created as part of theObject:
MyObject *theObject = [NSEntityDescription insertNewObjectForEntityForName:@"MyObject" inManagedObjectContext: myManagedObjectContext];
and initialized:
a1 = [[NSMutableArray alloc] init];
Objects are added to a1 with [a1 insertObject:[NSNumber numberWithInt:0] atIndex: 0 ];
Then I save the context after all that. Loading the context back all elements stored in a1 are saved and loaded. ALL WORKS WELL!
BUT when now a1 CHANGES, for example by adding one more element to a1 or changing any element within a1 and the context is being saved and loaded back, the content of a1 is UNCHANGED (it remains exactly as it was before all changes happened). CHANGES DON'T WORK!
By the way, while the app is running, all changes to a1 ARE STORED in a1.
Please, can you help - what is going on here?
Thanks ver much for your help!
Changes inside of your Array are not going to work because Core Data cannot see into the array.
The short answer is don't do this. This is no reason ever to store an array (or dictionary for that matter) in Core Data.
Create a new entity in Core Data and create a relationship. If the order is important, put an order attribute in the child table.
Do not store arrays as binary objects.
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