CoreData에 저장된 아티스트가 많으며 접두사 "the"를 무시하고 이름순으로 정렬하려고합니다. 그래서 예를 들어 "The Beatles"는 "Beatles"로 분류 될 것입니다. iTunes/iPod과 비슷합니다. 분명히 cleanName
와 같은 응용 프로그램을 제공합니다"the"접두사를 제거하는 NSSortDescriptor
NSSortDescriptor *sortByName = [[NSSortDescriptor alloc] initWithKey:@"cleanName" ascending:YES];
되지는 SQLEntity의 한 속성입니다 :
가 함께 정렬에 사용할 수 있도록 그래서 난 내 아티스트 모델에 사용자 정의cleanName
속성을 추가하는 시도
...keypath cleanName not found in entity <NSSQLEntity Artist id=1>
저장소에 cleanName을 저장할 수 있다는 것을 알고 있지만 그것은 나에게 잘못되었습니다. 이름에 "the"접두어가 없어 지도록 한 새로운 속성? 정말?
그래서 대신에, 나는 사용자 정의 compareObject와 NSSortDescriptor를 서브 클래스 시도 : toObject : 구현 : 나는 새로운 아티스트를 추가 할 때이 작동- (NSComparisonResult)compareObject:(Artist*)artist1 toObject:(Artist*)artist2 {
NSString *cleanString1 = [artist1.name stringByReplacingOccurrencesOfString:@"the " withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [artist1.name length])];
NSString *cleanString2 = [artist2.name stringByReplacingOccurrencesOfString:@"the " withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [artist2.name length])];
return [artist1.cleanName compare:artist2.cleanName options:NSCaseInsensitiveSearch];
}
, 내 가게에 "비틀즈"를 말한다. 아티스트는 "비틀즈"로 분류되어 내 "B"섹션에 표시됩니다. 그러나 곧 내가 그것을 응용 프로그램을 종료하고 다시 시작으로, 나는 다음과 같은 오류가 발생하고있는 tableview은 빈 유지 : 당신은 내가 로깅하고있는 무슨에서 볼 수 있듯이
sectionIndex A for Apparat
sectionIndex B for Bonobo
sectionIndex M for Misteur Valaire
sectionIndex M for Moderat
sectionIndex P for Paul Kalkbrenner
sectionIndex R for Röyksopp
sectionIndex B for The Beatles
NSFetchedResultsController ERROR: The fetched object at index 6 has an out of order section name 'R. Objects must be sorted by section name'
이 섹션의 제목은 비틀즈 (괜찮 '섹션 제목은 B 여야 함). 그러나이 기록은 "Bonobo"앞에 있어야하기 때문에 분류가 깨졌습니다.
이 문제를 해결하는 방법에 대한 아이디어가 있으십니까?
* cleanName *을 어떻게 구현 했습니까? 엔티티에 대한 일시적인 속성이있는 것처럼 보일 것입니다. – Huperniketes
NSFetchedResultsControllers에서 정렬을 위해 일시적인 속성을 사용할 수 없다고 확신합니다. – samvermette