NSArray Equivalent of Map

后端 未结 11 1774
萌比男神i
萌比男神i 2020-11-28 05:06

Given an NSArray of NSDictionary objects (containing similar objects and keys) is it possible to write perform a map to an array of specified key?

11条回答
  •  温柔的废话
    2020-11-28 05:49

    There is a special key-path operator for this: @unionOfObjects. Probably it replaced [collect] from previous versions.

    Imagine a Transaction class with payee property:

    NSArray *payees = [self.transactions valueForKeyPath:@"@unionOfObjects.payee"];
    

    Apple docs on Array Operators in Key-Value coding.

提交回复
热议问题