Search code examples
plistnsdictionarynslog

NSDictionary and plist


I have a plist file with string keys and number values. I think I managed to fill an NSDictionary object with the plist contents just fine with the code:

NSBundle* bun = [NSBundle mainBundle];
NSString* path = [bun pathForResource:@"Tempos" ofType:@"plist"];

tempos = [NSDictionary dictionaryWithContentsOfFile:path];


Now, here's the part I don't understand.

id object = [tempos objectForKey:@"Allegro"];
NSLog(@"bpm: %@", object);

Outputs the desired number, 168.

NSInteger beats = (NSInteger)[tempos objectForKey:@"Allegro"];
NSLog(@"bpm: %ld", beats);

Instead outputs, 43203.


More importantly, when I try

bpm = (NSInteger)[tempos objectForKey:@"Allegro"];

I get 43203 assigned to bpm. How do I get 168 assigned to bpm instead??


Solution

  • I think using this should work:

    int beats = [[tempos objectForKey:@"Allegro"] intValue];
    NSLog(@"bpm: %i", beats);