안녕하세요. 서버에서 JSON
응답을받을 때 데이터베이스를 업데이트하는 동기화 기능을 만들고 있습니다. 나는 다른 데이터 (새로운 기록 또는 업데이트 기존 레코드)이있는 경우 가져 오기는 여기 iOS Magical records import from array
- (void)updateWithApiRepresentation:(NSDictionary *)json
{
self.title = json[@"Name"];
self.serverIdValue = [json[@"Id"] integerValue];
self.year = json[@"Year of Release"];
self.month = json[@"Month of Release"];
self.day = json[@"Day of Release"];
self.details = json[@"Description"];
self.coverImage = json[@"CoverImage"];
self.thumbnail = json[@"Thumbnail"];
self.price = json[@"Buy"];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"dd/MMMM/yyy"];
NSDate *date = [formatter dateFromString:[NSString stringWithFormat:@"%@/%@/%@",self.day,self.month,self.year]];
self.issueDate = date;
}
하고 (coredata
및 magicalRecord
사용) (성능을 향상시키기 위해) 개최하려는 내 수입 방법
+ (void)API_getStampsOnCompletion:(void(^)(BOOL success, NSError *error))completionBlock
{
[[ApiClient sharedInstance] getStampsOnSuccess:^(id responseJSON) {
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_context];
NSMutableArray *stamps = [[NSMutableArray alloc]init];
[responseJSON[@"root"] enumerateObjectsUsingBlock:^(id attributes, NSUInteger idx, BOOL *stop) {
Stamp *stamp = [[Stamp alloc]init];
[stamp setOrderingValue:idx];
[stamp updateWithApiRepresentation:attributes];
[stamps addObject:stamp];
}];
[Stamp MR_importFromArray:stamps inContext:localContext];
} onFailure:^(NSError *error) {
if (completionBlock) {
completionBlock(NO, error);
}
}];
}
내가지고있어 오류
CoreData: error: Failed to call designated initializer on NSManagedObject class 'Stamp'
2016-08-02 23:52:20.216 SingPost[2078:80114] -[Stamp setOrdering:]: unrecognized selector sent to instance 0x78f35a30
Json 파서가 정상적으로 작동하는지 확인했습니다. 문제는 내 가져 오기 방법입니다. 나는 그 기능에 어떤 잘못이 있는지 모른다. 어떤 도움이라도 대단히 감사합니다. 감사!
안녕하세요, 저는 Magical Record libary에서 일하고 있습니다. 위의 값은 Stamp * stamp = [Stamp MR_createEntityInContext : localContext];와 같습니다. 새 레코드를 추가 할 때 중복을 피하는 방법은 없습니까? –
나는 Magical Record를 사용하지 않았기 때문에 확신 할 수 없다. –
어쨌든 (서버로부터 json 응답을받은 후) 중복 레코드를 추가하지 않는 방법을 알고 계십니까? –