Search code examples
iphoneobjective-cplist

Get the key from a dictionary object?


I have a dictionary set up like the one below. How can I get the actual key value (the actor's name) from objectAtIndex:1?

<plist version="1.0">
<dict>
    <key>Brad Pitt</key>
    <array>
        <string>Fight Club</string>
        <string>Seven</string>
        <string>Inglorious Basterds</string>
        <string>Babel</string>
    </array>
    <key>Meryl Streep</key>
    <array>
        <string>Adaptation</string>
        <string>The Devil Wears Prada</string>
        <string>Doubt</string>
        <string>Julie &amp; Julia</string>
    </array>
    <key>Chris Cooper</key>
    <array>
        <string>Adaptation</string>
        <string>American Beauty</string>
        <string>The Bourne Identity</string>
        <string>October Sky</string>
    </array>
</dict>
</plist>

Solution

  • I think you're looking for something like this?

    NSString *actorName = [[actorsDictionary allKeys] objectAtIndex:index];