Directly accessing nested dictionary values in Objective-C

后端 未结 3 840
后悔当初
后悔当初 2020-12-05 03:07

Is there a way to directly access an inner-array of an an outer array in Objective-C? For example, a call to an external data source returns the following object:



        
3条回答
  •  有刺的猬
    2020-12-05 03:37

    For nested keys like that you can use a keyPath. A keyPath is just a series of keys joined with dots. You can use them to retrieve nested values from objects that support Key-Value Coding - including NSDictionary objects like yours. So in your case this should work:

    [result valueForKeyPath:@"location.name"];
    

    For more detail on Key-Value Coding, see Apple's Key-Value Coding Programming Guide.

    See also this related StackOverflow question.

提交回复
热议问题