-私は
Item
エンティティとエンティティを持っていTag
ます。-アイテムは複数のタグを持つことができ、タグは複数のアイテムにリンクできます(多対多の関係)。-関係は、双方向で「順序付き関係」(IOS5の順序付き関係を使用)です。
特定のアイテムのすべての子タグを取得したい
次のフェッチ要求を使用しています。
NSFetchRequest* request = [NSFetchRequest fetchRequestWithEntityName:@"Item"];
// Fetch all items that have a given tag
Tag* myTag = ....;
request.predicate = [NSPredicate predicateWithFormat:@"ANY tag == %@", myTag];
// This is my attempt to get the correct sort ordering (it crashes)
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"tag"
ascending:YES];
request.sortDescriptors = @[sortDescriptor];
上記のソート記述子はデータを返しますが(これはある順序であると思います)、その後クラッシュします:
[_NSFaultingMutableOrderedSet compare:]: unrecognized selector sent to instance 0x10b058f0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[_NSFaultingMutableOrderedSet compare:]: unrecognised selector sent to instance 0x10b058f0'
空のソート記述子配列を指定すると、クラッシュは発生しませんが、結果は順序付けられません。
iOS5の順序付きリレーションシップ機能を使用して、多対多のリレーションシップでソート記述子を正しく実装するにはどうすればよいですか?