The following is the entity Player header file.
@interface Player : NSManagedObject
@property (nonatomic, retain) NSNumber * experience;
@property (nonatomic, retain) id items;
@property (nonatomic, retain) NSNumber * level;
@end
@interface items : NSValueTransformer
@end
items is essentially an NSMutableArray with NSNumber elements. And inside one function, I'm updating this array:
- (void)itemWasDropped:(ItemIndex)item
{ // _player has been correctly retrieved from the database
// the current number of this item
int nNum = [[_player.items objectAtIndex:item] intValue];
// to increment the number
[_player.items replaceObjectAtIndex:item withObject:[NSNumber numberWithInt:nNum + 1]];
}
This function gets called perfectly. I save the context in the viewWillDisappear function.
- (void)viewWillDisappear:(BOOL)animated
{ // _moc is an NSManagedObjectContext instance that has been correctly initialised.
// to update the database
NSError* err = nil;
BOOL bSucc = [_moc save:&err];
if (err || !bSucc)
{
...
}
}
The problem is that the updates are visible in other views as long as I do not shut down the app in the task bar. What's the problem? Anyone can help?
@propertyarray in the view controller class or whatever, and update the@propertyarray. Before database updating, the@propertyarray has to be assigned back to the entity attribute.