NSArray *FetchAllChefs(NSError **error) {
NSArray *chefs = nil;
// Create a request to fetch all Chefs.
NSEntityDescription *chefEntity = [NSEntityDescription entityForName:@"Chef" inManagedObjectContext:context];
NSFetchRequest *allChefsRequest = [[NSFetchRequest alloc] init];
[allChefsRequest setEntity:chefEntity];
// Ask the context for everything matching the request.
// If an error occurs, the context will return nil and an error in *error.
chefs = [context executeFetchRequest:allChefsRequest error:error];
// Clean up and return.
[allChefsRequest release];
return chefs;
}
- どこから取ってくるかNSEntityDescriptionで指定する
- NSFetchRequestを生成する
- 生成されたNSFetchRequestに対しNSEntityDescriptionを設定する
- 何も条件(where句)がなければそのままコンテキストに対しNSFetchRequest をexecuteFetchRequestで送る
でデータが取得できる模様。
戻ってくるのはNSManagedObjectの配列なので取り出すにはvalueForKey:を使う
コメントを残す