且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

根据另一个数组中对象的属性创建一个数组

更新时间: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.