0
我試圖用NSPredicate
過濾array
,但總是返回empty array
。使用NSPredicate過濾數組
代碼:
_contentFilteredArray = [_contentArray mutableCopy];
[_contentFilteredArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"special == 1"]]; // Always return an empty array.
原始_contentArray:
(
{
id = 1;
special = 0;
},
{
id = 2;
special = 1;
},
{
id = 3;
special = 1;
},
{
id = 4;
special = 0;
}
)
我希望_contentFilteredArray:
(
{
id = 2;
special = 1;
},
{
id = 3;
special = 1;
},
)
這應該工作,如果值是NSNumbers。試試這個日誌,看看它給了你什麼:NSLog(@「%@」,[_ contentArray [1] [@「special」] class]); – rdelmar 2013-04-28 05:47:36