I am using UIManagedDocument to manage my data. I create a model and use it, and everything seems to work, but my changes are not written to the SQLite repository.
The documentation for UIManagedDocument says that autosave should take care of storing data in the database, but this does not seem to happen.
NSManagedObjectContext *moc = [doc managedObjectContext]; NSError *error = nil; MyItem *itemToAdd = (MyItems *)[moc existingObjectWithID:(NSManagedObjectID *)itemsID error:&error];
Selects the object that I want to add (and successfully).
[itemContainer addItemsObject:itemToAdd]; [doc updateChangeCount:UIDocumentChangeDone];
This adds the item to the collection of items in another object, and then tells the document that I made the changes.
I expect some time soon afterwards to see the changes recorded in the Core Data repository, but looking in the "Tools", I see that this will never happen.
The collection of elements is an NSOrderedSet and due to comments on this element:
Exception thrown in NSOrderedSet-generated accessories
I added addItemsObject: to the object that contains the collection:
- (void)addItemsObject:(MyItem *)value { NSMutableOrderedSet* tempSet = [NSMutableOrderedSet orderedSetWithOrderedSet:self.items]; [tempSet addObject:value]; self.items = tempSet; }
It is possible that something is wrong when Core Data reports that the collection of elements has changed, but I donโt see how to do it.
stevex
source share