にコントローラ
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Album" inManagedObjectContext:manageContext];
album = [[Album alloc] initWithEntity:entity insertIntoManagedObjectContext:manageContext];
NSArray *arrayListAlbums = [album returnAllAlbums];
メソッドに
コード、あなたのNSManagedObject
サブクラス内の便利なメソッドを追加して、その後、あなたはにNSManagedObject
のインスタンスを作成しますその便利なメソッドを呼び出します。これは良いデザインではありません。
フェッチメソッドを呼び出すために空のデータオブジェクトを作成しています。おそらく、あなたは、クラスメソッドを持つべき「どこか」それは次のようになります。
あなたは、空のデータオブジェクト作成しなくてもアクセスすることができます
+ (NSArray *)returnAllAlbums:(NSManagedObjectContext*)moc
{
NSEntityDescription *entitydescription = [NSEntityDescription entityForName:@"Album" inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entitydescription];
NSError *error;
NSArray *arrayListAlbums = [managedObjContextAlbum executeFetchRequest:request error:&error];
if (arrayListAlbums == nil) {
NSLog(@"Failed to fetch: %@\n%@", [error localizedDescription], [error userInfo]);
}
return arrayListAlbums;
}
:私はViewControllerを以来returnAllAlbumsを呼び出すときに私はエラーが発生している
NSArray *arrayListAlbums = [MyClassWithFetchMethods returnAllAlbums:myLocalContextReference];
を – neo6583
エラーは何ですか? –