【发布时间】:2014-03-04 19:45:43
【问题描述】:
我发现了一个类似我的问题here,但我没有在答案中看到任何代码。
接下来是工作流程:
我使用下一个代码创建 NSManagedObject
[MagicalRecord saveInBackgroundWithBlock:^(NSManagedObjectContext *localContext) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"playerID == %@", responseData[@"player"][@"playerID"]];
Player *player = [Player MR_findFirstWithPredicate:predicate];
// on this line above player attributes are still the same at first time created. the player name is Alex if I po player.firstname in console.
// on this line below i import new name for player - Greg.
// so I print player.firstname and the console shows me Greg instead of Alex.
// I think it has to update my value but it does't when I try to print our it in the success block.
[player MR_importValuesForKeysWithObject:responseData];
} completion:^{
// here I want to get my players assuming that there is only one Player just for testing.
NSArray *arr = [Player MR_findAll]; // print arr.count = 1 (just test if i work with one and the same entity)
for (Player *p in arr) {
NSLog(@"%@", p.firstname); // type first name and it is Alex, but has to be Greg, because I have print out it after import line and player first name was Greg. But now it's still Alex. What the problem is?
}
}];
下一步我需要使用导入功能更新这个 NSManagedObject。我该怎么做?
【问题讨论】: