0
我有一個具有「n」個註釋對象的發佈對象。我正在使用MagicalRecord shouldImport在返回時創建空實體沒有
[publication MR_importValuesForKeysWithObject:dictionary];
用於從從解析到NSDictionary的服務器獲取的JSON中導入發佈和註釋對象。
在我的Comment.m文件中,我實現了shouldImport,因此只有在具有相同服務器ID的情況下才能創建一次Comment對象。
- (BOOL)shouldImport:(id)data {
Comment *comment = [Comment MR_findFirstByAttribute:@"server_id" withValue:data[@"server_id"] inContext:[NSManagedObjectContext MR_defaultContext]];
if (!comment) {
return YES;
}
return NO;
}
但由於某些原因,評論對象被創建反正,但與空數據。例如。我有一個關於server_id「1」的評論,並且我從服務器獲取這個對象多了3次,然後shouldImport被調用了3次,返回NO,但是創建了3個與正確的Publication對象相關的空對象。
我會做什麼錯?