Bill
Bill

Reputation: 3672

Nested objectForKey calls work, but equivalent valueForKey call doesn't?

I have an NSDictionary representing a Flickr photo.

The description of the photo looks like something like this:

{
    accuracy = 16;
    context = 0;
    dateupload = 1355106635;
    description =     {
        "_content" = "Barclays Center Arena\nAtlantic Yards\nProspect Heights\nBrooklyn, New York";
    };
    farm = 9;
    "geo_is_contact" = 0;
    "geo_is_family" = 0;
    "geo_is_friend" = 0;
    "geo_is_public" = 1;
    id = 8260097924;
    isfamily = 0;
    isfriend = 0;
    ispublic = 1;
    latitude = "40.681786";
    longitude = "-73.972545";
    originalformat = jpg;
    originalsecret = cd1bdd846a;
    owner = "62968578@N07";
    ownername = atlanticyardswebcam02;
    "place_id" = "uUNC_q9TWr1vROR4wA";
    secret = 320e308baa;
    server = 8502;
    tags = "newyork brooklyn construction prospectheights atlanticyards forestcityratner block1129 barclayscenterarena";
    title = "Barclays Center Arena - 20121209_2128";
    woeid = 28751452;
}

If I get the description via nested objectForKey calls, it works. I.e., like this:

NSString *photoDescription = [[photo objectForKey:@"description"] objectForKey:@"_content"];

That's clunky and my understanding is this should also work:

NSString *photoDescription_kv = [photo valueForKey:@"description._content"];

However, valueForKey always returns null.

What am I doing wrong?

Upvotes: 0

Views: 447

Answers (1)

Fourj
Fourj

Reputation: 1897

Should use valueForKeyPath instead.

NSString *photoDescription_kv = [photo valueForKeyPath:@"description._content"];

Upvotes: 5

Related Questions