I have an NSArrayController associated with a Core Data - Channel object. I have a method that updates an object after a user changes the channel name:
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread]; NSString * savedTitle = [fieldEditor string]; self.mainWindowController.selectedChannel.channel_name = savedTitle; [localContext MR_saveToPersistentStoreAndWait];
(I use MagicalRecord if this is not clear)
For all accounts, this save works - this value is reflected when changes are made, and if I immediately check the persistent storage using the Core Data Editor , I can see the change was saved.
The problem occurs when I change the view - the change is performed in the main view mode, and the user can switch to the detailed view. This line of code that swaps the main view marks the place where the problems are:
[[self.chatsViewController.view animator] removeFromSuperview];
After executing this line, the newly saved value will disappear. Requests to the entity attribute return an empty string.
But here is the weird part. If I restart the application, there is still a new value! He is returning, and this time he is here to stay. Also, when I look at a permanent store, I never see a value disappear at any moment. This suggests that my array controller is somehow getting a value.
I tried updating the array controller after saving in order to βlock itβ. But this has no effect.
Can anyone suggest what steps I can take to track this? I cannot understand why deleting the view will cause this to happen.
Update As I noted in my comment below, I tried to put the log statement in the name attribute attribute in my subclass of the object, and it gave a log entry when I changed the name, but never after.
Now I did another experiment: I look at the Core Data record both before and after the switch.
NSArray * channels = [Channel MR_findAll]; NSLog(@"Channel: %@", [[channels objectAtIndex:0] channel_name]); [[self.chatsViewController.view animator] removeFromSuperview]; NSArray * channels2 = [Channel MR_findAll]; NSLog(@"Channel2: %@", [[channels2 objectAtIndex:0] channel_name]);
Result:
Channel: adfasd Channel2:
Something is missing for me here.