0

我有一个带有字符串键和数字值的 plist 文件。我想我设法用 plist 内容填充了一个 NSDictionary 对象,代码很好:

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

tempos = [NSDictionary dictionaryWithContentsOfFile:path];


现在,这是我不明白的部分。

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

输出所需的数字,168

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

而是输出,43203.


更重要的是,当我尝试

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

我被43203分配到bpm. 我如何被168分配到呢bpm

4

1 回答 1

1

我认为使用它应该可以工作:

int beats = [[tempos objectForKey:@"Allegro"] intValue];
NSLog(@"bpm: %i", beats);
于 2012-07-27T16:15:20.093 回答