Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 非预测查询_Iphone_Objective C_Nspredicate - Fatal编程技术网

Iphone 非预测查询

Iphone 非预测查询,iphone,objective-c,nspredicate,Iphone,Objective C,Nspredicate,我以前使用过NSPredicate,但用途不同。但我被困在下面的场景中进行查询 我有数组Persons,其中包含Person对象,即Persons是对象数组。我需要从persons数组中的所有person对象中收集所有名称。我知道我们可以通过for-loop实现,但我们可以通过NSpredicate或更优化的方式实现吗 NSMutableArray *names; for (int i=0; i<[persons count]; i++) { [names addObject:[[p

我以前使用过NSPredicate,但用途不同。但我被困在下面的场景中进行查询

我有数组Persons,其中包含Person对象,即Persons是对象数组。我需要从persons数组中的所有person对象中收集所有名称。我知道我们可以通过for-loop实现,但我们可以通过NSpredicate或更优化的方式实现吗

NSMutableArray *names;
for (int i=0; i<[persons count]; i++)
{
   [names addObject:[[persons objectAtIndex:i] names_]];
}
NSMutableArray*名称;

对于(inti=0;i这一行就可以了

[PersonArray valueForKeyPath:@"@unionOfObjects.name"]

这一行就行了

[PersonArray valueForKeyPath:@"@unionOfObjects.name"]

@cmk Ya,你知道了。谢谢。更新。@“@可能会让人难以键入。:)谢谢你更新。@cmk Ya,你知道了。谢谢。更新。@“@可能会让人难以键入。:)谢谢你的更新。