我不是在語法predicateWithFormat:
的專家,但已經具備了基本依據。您可以在Apple的Predicate Programming Guide中找到有關格式的詳細信息。如果你問到與謂詞做,一旦你擁有了它,這裏是你展示的步驟片段:
// Create a fetch request.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Set the entity for the fetch request.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"EntityName" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
[entity release];
// Set the predicate for the fetch request.
[fetchRequest setPredicate:predicate];
// Perform the fetch.
NSError *error;
NSArray *array = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
[fetchRequest release];
如果你想要的結果進行排序,你可以通過排序描述符的數組在執行提取之前使用setSortDescriptors:
對提取請求進行提取。