2つのコアデータエンティティがArticles
ありFavorite
ます。Articles
To-Manyとの関係がありFavorite
ます。まず、すべてのArticles
オブジェクトを正常に挿入しました。
現在、「お気に入り」エンティティにArticleIDを挿入しようとしていますが、挿入できません。レコードが空の関係で挿入されるか、「Articles」エンティティに新しいレコードで挿入されます。
Articles
最初にエンティティの関連レコードを取得してから、それを使用して挿入する必要があると思いますが、Favorite
これを行う方法がわかりません。私の現在のコード:
NSManagedObjectContext *context =[appDelegate managedObjectContext] ;
favorite *Fav =[NSEntityDescription insertNewObjectForEntityForName:@"favorite" inManagedObjectContext:context];
Articles * Article = [NSEntityDescription insertNewObjectForEntityForName:@"Articles" inManagedObjectContext:context];
NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Articles" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSPredicate *secondpredicate = [NSPredicate predicateWithFormat:@"qid = %@",appDelegate.GlobalQID ];
NSPredicate *thirdpredicate = [NSPredicate predicateWithFormat:@"LangID=%@",appDelegate.LangID];
NSPredicate *comboPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects: secondpredicate,thirdpredicate, nil]];
[fetchRequest setPredicate:comboPredicate];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *info in fetchedObjects) {
// ?????????????????????????
}
}
任意の提案をいただければ幸いです。