Xcode Obj-C: Make new NSArray from one key each out of an Array of Dictionaries
This actually could be a multipart question. But h开发者_运维知识库ere's the first part ...
I have an array (actually in a plist) of dictionaries. Each dictionary has 3 keys in it: (title), (points), and (description).
I am trying to make a NEW array with the values of the key "title" from each dictionary in that first array.
Let me explain WHY I am doing this and maybe that will provide a better all around explanation.
I am trying to let people pick from a pre-determined list. Heck, if this was a web page it would be very simple since all I really care about are the "points" and the "Title". On a web site I could simply do a drop down combo-box with the "points" being the value and the title being the text for each row.
But this is not a web page.
So what I am trying to do here is pop out a modal picker when they click the text field. The modal picker shows the alphabetical ordered "titles" from our new array. And whichever one they select, it closes the modal view and assigns that "title" text to the UITextField
which cannot be edited by the user.
I have some code to get my modal picker to pop out. But I need to feed it an array of just the "titles" of each dictionary in my real array.
[array valueForKeyPath:@"title"]
That should return a new array with the result of calling [obj valueForKey:@"title"] on each object in the array.
In this case, you should be able to just use
[array valueForKey:@"title"]
as well, but if you wanted to go further into the dictionary (like "person.name" or something), the key-path version is very nice.
精彩评论