でコアデータの問題が発生していNSFetchedResultsController
ます。親と子のエンティティの間には1対多の関係があります。プロパティ内の配列はchildFetchedResults.fetchedObjects
並べ替えられませんnumber
(数値はモデル内のint32プロパティです)。MagicalRecord
コンビニエンスカテゴリメソッドを使用するかどうかは問題ではないようです。
NSFetchRequest *req = [Child MR_requestAllSortedBy:@"number" ascending:YES withPredicate:[NSPredicate predicateWithFormat:@"parent = %@", self.parent]];
childFetchedResults = [[NSFetchedResultsController alloc] initWithFetchRequest:req managedObjectContext:[NSManagedObjectContext MR_defaultContext] sectionNameKeyPath:nil cacheName:nil];
childFetchedResults.delegate = self;
NSError *error;
[childFetchedResults performFetch:&error];
NSLog(@"fetched objects: %@", childFetchedResults.fetchedObjects);
ただし、まったく同じ並べ替え記述子を使用してフェッチされたオブジェクトの配列を並べ替えると、正常に機能します。
NSLog(@"fetched objects: %@", [childFetchedResults.fetchedObjects sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"number" ascending:YES]]]);
フェッチ要求のソート記述子を指定するときにCoreDataがSQLiteストアに渡すことができるコンパレーターのみを使用できることを私は収集します。しかし、SQLiteでは数値による並べ替えがサポートされている必要があるため、この場合は問題にならないように感じます。
誰かがこれを解決しましたか?ここで説明されている問題と同様の問題のように感じます:NSSortDescriptorが呼び出されていません。
に関してはMR_requestAllSortedBy
、それはMagicalRecord
にあります、ここに実装があります:
+ (NSFetchRequest *) MR_requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context
{
NSFetchRequest *request = [self MR_requestAllInContext:context];
NSSortDescriptor *sortBy = [[NSSortDescriptor alloc] initWithKey:sortTerm ascending:ascending];
[request setSortDescriptors:[NSArray arrayWithObject:sortBy]];
return request;
}