1

New to Xcode and obj-c.

Is it possible to sort through data structures in the console like you with JavaScript?

-(void)fetchInfo
{
    NSURL *url = [NSURL URLWithString:@"http://someurl"];
    NSData *jsonResults = [NSData dataWithContentsOfURL:url];
    NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:jsonResults
                                                             options:0
                                                               error:NULL];
   NSLog(@"CitiBike Results = %@", dictionary);

}

The results are logged, but I now want to play with the returned dictionary

Larme
  • 24,190
  • 6
  • 51
  • 81
user2954587
  • 4,661
  • 6
  • 43
  • 101

1 Answers1

4

If you make a mutable copy, you can fiddle with that in the console

NSMutableDictionary *mutableDictionary = [dictionary mutableCopy];

then

p mutableDictionary[@"key"] = @"Hello, World!"

EDIT: you can also store it in a convenience variable in lldb like

expr NSMutableDictionary *$md = mutableDictionary

so that if it goes out of scope, as long as it's alive, you can still access it in the debugger like

p $md[@"key"] = @"Convenience!"
Adlai Holler
  • 830
  • 7
  • 10
  • I think I'm missing something. I can log the mutable dictionary but when I call p md[@"key"] after the build succeeds nothing is returned. – user2954587 Apr 28 '14 at 18:32
  • well if you call `p md[@"key"] = @"test"` then nothing will be returned. But afterward if you call `po md` or `po md[@"key"]` you'll see the newly added pair. – Adlai Holler Apr 28 '14 at 18:40