Ray Wenderlich's new tutorial 다음으로 JSON 데이터를 가져 와서 코어 데이터에 저장할 수있었습니다. 코어 데이터의 관계를 통해이를 수행하는 방법을 이해하는 데 어려움을 겪고 있습니다. 여기 JSON과 관계가있는 코어 데이터
{
"results": [
{
"name": "Trivia 1",
"objectId": "1000",
"createdAt": "2012-08-31 18:02:52.249 +0000",
"updatedAt": "2012-08-31 18:02:52.249 +0000",
"questions": [
{
"text": "Question 1"
},
{
"text": "Question 2"
},
{
"text": "Question 3"
}
]
}
]
}
그리고 마지막으로 여기에 내가 managedObject의 값으로 설정 곳이다 :
//Sets values for ManagedObject, also checks type
- (void)setValue:(id)value forKey:(NSString *)key forManagedObject:(NSManagedObject *)managedObject {
NSLog(@"TYPE: %@", [value class]);
//If managedObject key is "createdAt" or "updatedAt" format the date string to an nsdate
if ([key isEqualToString:@"createdAt"] || [key isEqualToString:@"updatedAt"]) {
NSDate *date = [self dateUsingStringFromAPI:value];
//Set date object to managedObject
[managedObject setValue:date forKey:key];
} else if ([value isKindOfClass:[NSArray class]]) { //<---This would be the array for the Relationship
//TODO: If it's a Dictionary/Array add logic here
for(NSDictionary *dict in value){
NSLog(@"QUESTION");
}
} else {
//Set managedObject's key to string
[managedObject setValue:value forKey:key];
}
}
I를 여기
내 데이터 모델입니다 this question을 살펴 보았습니다. 그러나 나는 정말로 혼란스러워합니다. 레이 Wenderlich 예제에서 함께 조각을 연결합니다. 어떤 도움이라도 대단히 감사하겠습니다.
감사 봐, 이것은 내가 지금 필요한 작동하게한다. 나는 미래에 필요할 때 더 유연하게 작업 할 것입니다. – mkral
이 코드는 동기화 할 때 중복 된 관리 대상 객체를 어떻게 처리합니까? 이 코드가 실행될 때마다 새로운 객체를 삽입하는 것처럼 보입니다. – bluemoon
이 블록은이를 처리하지 않습니다. 동기화 중에 데이터 복제가 처리되어야합니다. –