CoreDataデータベースを使用しています。エンティティAlbumがあり、多くのエンティティSpecificImageがあります(これらの画像のセットを取得するためのキーは@ "specificImages"です)id = 1のAlbumを取得し、添付されたSpecificImagesをidで並べ替えます。私は試した
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"specificImages.id" ascending:YES];
しかし、私はエラーが発生します
キャッチされなかった例外'NSInvalidArgumentException'が原因でアプリを終了しています、理由:'to-manyキーはここでは許可されていません'
これが私のコードです:
NSString *entityName = kEntityName;
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];;
NSManagedObjectContext *context = appDelegate.managedObjectContext;
NSEntityDescription *entityDesctiption = [NSEntityDescription
entityForName: entityName
inManagedObjectContext:context];
// find object
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id == %d", CurrentCategoryItemID];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"specificImages.id" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[request setEntity:entityDesctiption];
[request setPredicate:predicate];
NSArray *objects = [context executeFetchRequest:request error:nil];
[request release];
if (objects == nil)
{
NSLog(@"there was an error");
return;
}
else if ([objects count] == 0)
{
return;
}
NSManagedObject *object = [objects objectAtIndex:0];
NSArrayを実行しようとすると例外がスローされます*objects= [context executeFetchRequest:request error:nil];