1
假設數據實體是:Bookshop <--->> Books
如何獲取核心數據中的一對多關係?
如何獲取屬於特定書店的名稱中包含「雲」的所有書籍,例如?以下方法感覺笨重。
Bookshop *bookshop = (Bookshop *) nsManagedObjectFromOwner;
NSString *searchTerm = @"cloud";
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Books"
inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"ANY bookshop.Name == '%@' && Name contain[cd] '%@'",
bookshop.Name, searchTerm];
[fetchRequest setPredicate: predicate];
我該如何改進這個代碼來處理,如果有2個名稱非常相似的書店?也可能是因爲UITableView應該更新爲書名中的用戶類型而提高了讀取性能。