iPhone development Objective-C: NSArray access individual elements
I'm using Kumulos to store a database for my iPhone app and eve开发者_如何学编程rything works well except the select method.
This method is called when I perform a select on database :
-(void) kumulosAPI:(Kumulos*)kumulos apiOperation:(KSAPIOperation*)operation crissDidCompleteWithResult:(NSArray*)theResults;
{
NSString *poche = [theResults objectAtIndex:0];
NSLog("%@",poche);
}
As you can see the method return the NSArray and this is what I am getting from the log console.
2011-03-23 00:59:18.844 GpsProject[8708:207] {
location = "Rue de Lisieux";
name = tayeul;
timeCreated = "2011-03-22 17:31:32 +0000";
timeUpdated = "1999-11-30 00:00:00 +0000";
userID = 10;
}
but I want this data not in one NSString, I want it separate. For example I need the "location"... I can't get it.
The results array looks more like an array of NSDictionary. So you can easily access the individual elements using the Key value for the dictionary. For example if you want to access location you can do so by
NSString *location = [[theResults objectAtIndex:0] objectForKey:@"location"];
Hope this helps.
The object in the array might be a dictionary. Try:
NSString *poche = [[theResults objectAtIndex:0] objectForKey:@"location"];
NSLog("%@",poche);
I don't have any idea about kumulos so above is just a guess.
精彩评论