The NSArrayController object attribute mysteriously fell out

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.

+7
objective-c cocoa core-data nsarraycontroller
source share

No one has answered this question yet.

See related questions:

1818
What is the difference between atomic and non-atomic attributes?
372
Master data: the fastest way to delete all instances of an object
12
Disable MagicalRecord error messages and warnings
2
NSArrayControllers and heterogeneous arrays of Core Data objects
2
_PFFaultHandlerLookupRow error while saving child context
one
How to save quick property changes from the UI (main) topic
one
NSCollectionView Compatibility with CoreData
one
What do you need to implement to provide a content set for NSArrayController?
0
Issues with master data persisting when changes are made to entities
0
Update attribute in MagicalRecord

All Articles