我用這個代碼來選擇與特定類別的所有產品,但它不工作,,什麼是正確的斷言,我可以用於獲得所有與此類別相關的產品
注意: 我從服務器上單獨獲取類別列表並插入它們,然後從服務器獲取產品列表並插入它們,但是現在我發現該產品並沒有不知道他的類別,我使用restkit庫來解析並插入到數據庫中,所以我如何告訴產品該類別,restkit自動完成所有工作
如何將產品列表設置爲我從服務器獲得的類別?
//--fetching inserted Results from core data
// Getting products
NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"productId" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor , nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category = %@ ",tempCategoryHolder];
// [fetchRequest setPredicate:predicate] ;
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Product"
inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
fetchedObjectsProducts = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
謂詞爲什麼被註釋掉?它是如何工作的?什麼是'tempCategoryHolder'?如果你登錄'tempCategoryHolder.products',你會得到什麼? – Wain
不,我只是評論它,因爲代碼不能很好地工作 – mohamed
顯示你的映射。你需要做一個外鍵映射連接... – Wain