I have an NSDictionary filled with data. If this was php it might be accessed by something like:
$data = $array['all_items'][0]['name'];
How do I do something similar in objective c? ($array would be an NSDictionary)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The equivalent code in Objective-C is:
Note that
objectForKey:is a method of NSDictionary, andobjectAtIndex:is a method of NSArray.A shortcut in Xcode 4.5, using LLVM 4.1, is:
Also note that if “array” is an NSDictionary instance and you want to get an array of all values in the dictionary, you use the
allValuesmethod of NSDictionary:Of course,
allValuesreturns an unsorted array, so accessing the array by index is not very useful. More typically, you’d see: