更新时间:2022-06-22 22:29:08
这将返回一个数组,其中包含myCars
数组中每个项目的licensePlate
值:
This will return an array containing the value of licensePlate
from each item in the myCars
array:
NSArray *licensePlates = [myCars valueForKeyPath:@"licensePlate"]
例如,如果只需要唯一项,则可以执行以下操作:
If you want only unique items (for example), you can do something like this:
NSArray *licensePlates = [myCars valueForKeyPath:@"@distinctUnionOfObjects.licensePlate"];
有关更多可能性,请参见键值编码编程指南.
For more possibilities, see the Collection Operators documentation in the Key-Value Coding Programming Guide.