我正在尝试NSArray
通过 ' function
' 属性搜索。我在控制台上打印数组时的输出如下:
<__NSArrayI 0xa523b40>(
{
category = "010-T";
description = "<h3>Opleidingen</h3>";
function = "T-r";
name = "Michal Jordan";
photo = "http://dws.com/34.jpg";
},
{
category = "010-T";
description = "abcd";
function = "AB";
name = "Pvt MSK";
photo = "http://test.com/3.jpg";
},
{
category = "010-T";
description = "def";
function = "T-r";
name = "Sanu M";
photo = "http://abc.com/1.jpg";
}
)
此代码按“ category
”搜索,有效:
NSString *categoryStr = @"010-T";
NSArray *arr = [NSArray arrayWithArray:[myarr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"category == %@",categoryStr]]];
但是当我尝试使用以下代码(按 搜索function
)时,抛出了异常:
NSString *functionStr = @"T-r";
NSArray *arr = [NSArray arrayWithArray:[myarr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"function == %@",functionStr]]];
例外是:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "function == %@"'
所以在这里看来,这function
是一个保留关键字。
我尝试了以下代码,function
用单引号括起来,但结果是arr
有 0 个对象。
NSArray *arr = [NSArray arrayWithArray:[myarr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"'function' == %@",functionStr]]];
我在这里做错了什么?