問題の回避策はありますが、なぜこの問題が発生しているのか、そしてどのように解決するのかを本当に理解したいと思います。
別のエンティティBに関連するエンティティAがあり、Aの行の一部に1つのフィールドに特別なマークがあります。
この特別なマークが付いている、Bに関連するAの数を数えたいと思います。
NSSetを作成した後、セットを数えると、すべてが完全に機能します。
NSSet *productsSet = currentList.ingredients;
int countProducts = productsSet.count;
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"self IN %@ AND isInList = %d", productsSet,1];
[fetchRequest setPredicate:predicate];
int totalProductsInList = [context countForFetchRequest:fetchRequest error:error];
int countProducts=productsSet.count;にコメントすると 私はそれらのエラーがあります:
-[NSNull unsignedIntValue]: unrecognized selector sent to instance 0x22b9cd8
2011-12-05 12:10:41.418 xxxxxxxxxx[32964:1bb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[NSNull unsignedIntValue]: unrecognized selector sent to instance 0x22b9cd8'
isInListはInt16です
ありがとう、
編集:
カウントせずにNSPredicate内で1を移動すると、同じエラーが発生します。
[NSPredicate predicateWithFormat: @"self IN %@ AND isInList = 1", productsSet;
編集2:
なぜ機能しないのかわからないので、productsSet.countをチェックし、0より大きい場合は、NSFetchrequestを実行して、問題を解決しました。