Search code examples
iosobjective-cnsmutablearraynsarraynslog

ValueForKey: returns result in an array


I have an array that looks like this:

 {
    name = Size;
    "option_id" = 13;
    "product_option_id" = 380;
    required = 1;
    type = select;
}     

and when i log an output like so:

NSLog(@"productOptions %@",[self.singleProductOptionsArray valueForKey:@"name"]);

it outputs the result inside an array so i cannout put it into a string:

 2013-08-01 11:10:33.116 vinylsdirect[210:907] productOptions (
 Size
)

i am using the same code in other arrays and everything is working fine so im not sure what is going on. i have also tried changing the NSLog like so:

NSLog(@"productOptions %@",[[self.singleProductOptionsArray objectAtIndex:0] valueForKey:@"name"]); 

Does anyone have any idea what might be causing my issues?

Thanks


Solution

  • I think its an nsarray containing nsdictionarys. Iterate over it. See if this works ?

    for (NSDictionary *prod in self.singleProductOptionsArray)
    {
        NSLog(@"Prod: %@", [prod valueForKey:@"name"]);
    }