2

in PHP when using an array you can use myArray['firstElement'] to pull that specific key and its associated values from the array. How do I do this similar type of thing in objective c?

3
  • 1
    When you say 'array', do you mean a primitive array like int[], an ordered collection like NSArray, or an associative collection like NSDictionary? Commented Jun 20, 2011 at 5:44
  • an NSArray but I solved my problem. By using [myArray objectForKey:@"firstElement"]; it returns that specific segment. thanks Commented Jun 20, 2011 at 5:48
  • If you're new to Obj-C, please read the guide The Objective-C Programming Language. Commented Jun 20, 2011 at 5:48

2 Answers 2

4

If you want to deal with key-value pairs, you would use an NSDictionary.

Although it is surprising to note that arrays in PHP are an ordered map.

Sign up to request clarification or add additional context in comments.

1 Comment

To access the key use [dict valueForKey:@"key"]
1

You want to use NSDictionary instead of NSArray. NSDictionary is an associative array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.