Search code examples
objective-cnslog

How do I NSLog a string from an NSDictionary object?


Working with Json, how can I "NSlog" only the title in this code:

NSDictionary *item = [tableData objectAtIndex:[indexPath row]];
    // Set text on textLabel
    [[cell textLabel] setText:[item objectForKey:@"title"]];
    // Set text on detailTextLabel
    [[cell detailTextLabel] setText:[item objectForKey:@"description"]];

Something like NSlog(@"%@", title); ?

Thanks!


Solution

  • If I have understood what you are asking correctly, then this should do it:

    NSLog(@"%@", [item objectForKey:@"title"]);
    

    If that gives you a compiler warning because the object may not be an NSString, then you can do:

    NSString *title = [item objectForKey:@"title"];
    NSLog(@"%@", title);
    

    If I've misunderstood your question, please let me know and I will correct my answer accordingly.