0

I would like to return the value of "star_rating" from this NSDictionary retrieved using MKLocalSearch. The dictionary that is returned looks something like this after I apply valueForKeyPath:@"business" to it.

UID = 8094514780070527910;
URL = "http://www.uvm.edu";
attribution =     (
            {
        attributionURLs =             (
            "yelp5.3:///biz/university-of-vermont-burlington",
            "yelp4:///biz/university-of-vermont-burlington",
            "yelp:///biz/university-of-vermont-burlington",
            "http://yelp.com/biz/university-of-vermont-burlington"
        );
        sourceIdentifier = "com.yelp";
        sourceVersion = 1;
    }
);
canBeCorrectedByBusinessOwner = 1;
name = "The University of Vermont";
source =     (
            {
        "source_id" = 647659235;
        "source_name" = "geo_id";
    },
            {
        "source_id" = dBeQ7Nq1LcngfTz7gKrjLA;
        "source_name" = yelp;
    },
            {
        "source_id" = A3H0613898;
        "source_name" = "acxiom_us";
    },
            {
        "source_id" = A1L0080070;
        "source_name" = "acxiom_us";
    },
            {
        "source_id" = A3H0614039;
        "source_name" = "acxiom_us";
    },
            {
        "source_id" = "university-of-vermont-burlington";
        "source_name" = "yelp_alias";
    }
);
"star_rating" =     (
    "4.5"
);
telephone = "+18026563131";}

My Code:

            MKMapItem *firstMapItem = [response.mapItems objectAtIndex:0];

            NSDictionary *bizdic = [firstMapItem valueForKeyPath:@"business"];

            NSLog(@"%@", bizdic);

            //Problem Occurs Here 
            NSLog(@"%@", [bizdic valueForKeyPath:@"\"star_rating\""]);

Every time I go to print the value of "star_rating" to the console the app crashes and produces the following error:

    *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<GEOBusiness 0x160c5f20> valueForUndefinedKey:]: this class is not key value coding-compliant for the key "star_rating".'

If I use a value like telephone instead of "star_rating" it returns the telephone number no problem. This is my first time using MKLocalSearch so any advice is appreciated.

  • Get rid of the quotes in your key path. You want a path of `@"star_rating"`. – rmaddy Aug 08 '14 at 03:33
  • 1
    The `bizdic` object that is returned is not a dictionary. It is actually a GEOBusiness object which seems to be undocumented. When you NSLog it, what you see is its description of itself and "star_rating" is apparently not how you can actually access that value (even without the quotes). Related: http://stackoverflow.com/questions/24300138/ios-mkmapitem-how-get-access-to-all-members. It's unfortunate that MKMapItem's description is showing useful data that you can't access in a documented way. –  Aug 08 '14 at 03:51

0 Answers0