+1  A: 

You can look up the value for a key in a dictionary using objectForKey:. For example:

NSString* exercise = [dictionary objectForKey:@"OIK74"];

See the NSDictionary Class Reference for more information.

Will Harris
True, but how do I get the corresponding Exercise value( "testing"). Because like this you are filling an Exercise string with the key value.
That method does retrieve the value 'testing'. If you also need to get the keys - i.e. if you don't know them in advance, you're just handed some dictionary - then the NSDictionary class also has methods to do retrieve all the keys and all the values. See the class reference link provided by Will.
frankodwyer
A: 

I think the OP wants to get "testing" by searching for "OIK74".

The first thing I would suggest is that you make OIK74 the key and then fetching out the string value is trivial. If each of your rows has the same Exercise key, that seems redundant when it appears that ID is actually an ID that should be unique and would serve quite well as a key.

If you're set on this data arrangement (which I'll say again I think should be revisited if possible) then you're looking at something different from simple keypath drilling. You're looking for the value of a sibling node in the dictionary for your particular row. NSXMLDocument can do this quite easily with xpath queries I believe. The conceptual barrier here is that NSDictionary mirrors the structure of plists, but an NSDictionary is not really XML. You don't have tags and values. You have keys and values. In the XML/plist representation of the NSDictionary, the tags are <key> and <value> and your NSDictionary keys and values are the values in those tags.

I'm not 100% sure what the internal structure of the data you've outlined is, but it looks like you have something like

root = (
    item1 = { 
        Exercise = "testing",
        ID = "OIK74"
    }
    item2 = {
        Exercise = "testing3",
        ID = "424RE"
    }
    item3 = {
        Exercise = "testing5",
        ID = "RET23"
    }
)

in text plist format. Is that right? If so, what I would propose is rearranging this entirely into a much more simple structure:

{
    "OIK74" = "testing",
    "424RE" = "testing3",
    "RET23" = "testing5"
}

If you have more data for those IDs, then you can set a dictionary as the value for the key like this:

{
    "OIK74" = { 
        "Exercise" = "testing",
        "OtherDataPoint" = "othervalue"
    },
    "424RE" = { 
        "Exercise" = "testing3",
        "OtherDataPoint" = "othervalue3"
    },
    "RET23" = { 
        "Exercise" = "testing5",
        "OtherDataPoint" = "othervalue5"
    }
}

Since you mentioned that the OIK74 value that you're looking for is a key, this approach makes much more sense IMHO. With this new data structure, you would get the value "testing" with either [dictionary valueForKey:@"OIK74"]; or [dictionary valueForKeyPath:@"OIK74.Exercise"]; respectively. Hope that helps.

jxpx777