【发布时间】:2011-12-05 17:33:15
【问题描述】:
我有一个多维可变数组,其中包含每个维度中的各种对象。
位置 1 = foodID int,位置 2 = itemName NSString
即。
Row 1 [1, "Jif"];
Row 2 [2, "Skippy"];
Row 3 [3, "Peter Pan"];
当我尝试使用下面的以下代码时,它会引发异常,因为它会尝试将位置 1 评估为字符串
//---get all Peanut Butter Types beginning with the letter---
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
NSArray *beginWith = [food filteredArrayUsingPredicate:predicate];
例外
'NSInvalidArgumentException', reason: 'Can't do a substring operation with something that isn't a string'
谁能帮助我如何使用谓词过滤多维数组的特定列?
NSDictionary 有很多这样的例子,它可以应用于键,但我似乎无法将它应用于数组中的特定位置。
【问题讨论】:
标签: objective-c xcode nsmutablearray nspredicate