코어 데이터베이스를 사용합니다. 많은 엔티티 SpecificImage (이러한 이미지 세트를 가져올 키는 @ "specificImages"입니다.) id = 1 인 앨범을 가져오고 id로 연결된 SpecificImages를 정렬하려고합니다. 나는NSSortDescriptor 대단위 관계
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"specificImages.id" ascending:YES];
을 시도하지만 난 오류가 여기에
내 코드입니다 : 내가있는 NSArray * 객체 = [컨텍스트를 실행하려고 할 때Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'to-many key not allowed here'
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];
그것은 예외를 throw executeFetchRequest : 요청 오류 : nil];
첨부 된 이미지를 정렬하고 이미지를 정렬 한 다음 앨범을 반환하지 않으려합니다. 그래서 [NSSortDescriptor sortDescriptorWithKey : @ "specificImages.id"와 같은 것을 사용해야합니다 : 오름차순 : YES]; –
specificimages는 nsset 객체입니다. 그래서 id가 없습니다 .. fetchRequest에 sortdescriptor를 추가하면 결과 객체의 키 값을 비교하여 결과 배열을 정렬합니다. –
최선의 해결책은 무엇입니까? UR 문제에 대한 .. 거기에 하나 이상의 덜 효율적인 솔루션입니다 .. fetchRequest ..에 어떤 sortdescriptors를 포함하지 않을 것이다 당신이 원하는 앨범을 가져 와서 다음 해당 specifsimages nsset에 액세스하고 원하는대로 UR 욕구를 정렬 –