2014-03-04 2 views
0

내 질문에 here과 같은 질문이 있지만 답변에 코드가 표시되지 않습니다.MagicalRecord에서 기존 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를 업데이트해야 다음 단계를 사용하여 NSManagedObject를 만들 수 있습니다. 어떻게해야합니까?

답변

1

이것 좀보세요. blog post. 가져 오기 기능을 사용하기위한 모든 비 코드 관련 옵션에 대해 설명합니다.

+0

처음에는 모든 질문에 도움을 주셔서 감사합니다. MagicalRecord는 내가 본 아주 좋은 것입니다.) 내가 편집 한 코드를 확인할 수 있습니까? 어쩌면 이미 가져온 레코드와 존재하는 레코드로 작업하는 다른 방법이있을 수 있지만, 나는 술어로 레코드를 찾은 다음 MR_importValuesForKeysWithObject 메서드를 사용하여 개체를 수정하려고 약간의 임시 해결책을 취합니다. 그래서 어쩌면 좋지는 않지만 보이게 될 것 같습니다. 어떻게 생각해? 내가 수정하거나 개체의 데이터를 인쇄하는 각 줄에 주석을 추가했습니다. 업데이트 된 질문을 볼 수 있습니까? 정말 고마워. –

+0

가져 오기가 2.0.8 버전에서 유용하다는 문제점을 발견했습니다. 내 코드에서 localContext가 누락되었습니다. Player * player = [플레이어 MR_findFirstWithPredicate : predicate inContext : localContext]; 모든 것이 나를 위해 잘 작동합니다 ... –

+0

내 질문과 동일한 질문을 할 수있는 다른 사람들에게이 질문을 저장해야합니까? 어떻게 생각해? –