Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking changes to Core Data fetched array
    primarykey
    data
    text
    <p>Here's what I have:</p> <pre><code>NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"NoteObject" inManagedObjectContext:appDelegate.managedObjectContext]; [fetchRequest setEntity:entity]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(parentNoteId == %@) AND (noteId!=rootNoteId)", appDelegate.currentNoteId]; [fetchRequest setPredicate:predicate]; NSError *error; [appDelegate.arrayOfNotes setArray:[appDelegate.managedObjectContext executeFetchRequest:fetchRequest error:&amp;error]]; NoteObject *note=[appDelegate.arrayOfNotes objectAtIndex:0]; [note.arrayOfTags addObject:someObject]; NSManagedObjectContext *context = [appDelegate managedObjectContext]; if (![context save:&amp;error]) { NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]); } </code></pre> <p>The fetch works fine, and adding an object to the <code>arrayOfTags</code> works and reflects in the UI. However, when I exit the app and come back, the <code>arrayOfTags</code> is missing the one that I added (but it has the other two, so I know the array is working properly). It's not saving for some reason.</p> <p>(The <code>NoteObject</code> is a subclass of <code>NSManagedObject</code>, and <code>arrayOfTags</code> is a transformable property of the entity.)</p> <p>Am I doing something wrong here?</p> <p>Edit: Here's how I add a new note, which saves just fine, even with the arrayOfTags, and everything is saved when I exit the app and come back in. </p> <pre><code>NSManagedObjectContext *context = [appDelegate managedObjectContext]; NSEntityDescription *noteEntity = [[appDelegate.managedObjectModel entitiesByName] objectForKey:@"NoteObject"]; NoteObject *tempNote = [[NoteObject alloc] initWithEntity:noteEntity insertIntoManagedObjectContext:context]; [tempNote.arrayOfTags addObject:@"tag1"]; NSError *error; if (![context save:&amp;error]) { NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]); } </code></pre> <p>It's only when I make changes that it's not saved properly..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload