JSON データを提供する API からデータをインポートしています。コア データに追加される各オブジェクトには、「id」という名前の属性があります。最初のインポート後に ID が既にコア データに含まれているかどうかを確認できるようにしたいと考えています。これまでのところ、このコードを書きました:
- (void)mergeData: (NSString *)entityDescription {
NSPredicate *pred = [NSPredicate predicateWithFormat:@"id == %@", _bank.id]; // Bank is the entity
// id is the key from the raw JSON
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
NSError *error = nil;
[fetch setEntity:[NSEntityDescription entityForName:@"Banks" inManagedObjectContext:self.managedObjectContext]];
[fetch setPredicate:pred];
NSArray *items = [self.managedObjectContext executeFetchRequest:fetch error:&error];
for (NSManagedObject *object in items) {
// Loop over all the items and check to see if the ids match with any ids from the feed
// if any of them don't match, add the new ids
if (!match) {
// add new object
// I'm not sure how to implement this part
}
}
しかし、それが完全ではないことはわかっており、この部分の残りのコードを実装する方法がわかりません。どんな助けでも大歓迎です。