【发布时间】:2014-09-23 20:50:43
【问题描述】:
我很难理解如何使用 Objective-C 访问数组中的值 我的数组看起来像这样:
bualadhBos = @[
@{ @"time":[NSNumber numberWithInt:2875],
@"line" : @"Muid uilig ag bualadh bos, "},
@{ @"time":[NSNumber numberWithInt:3407],
@"line": @"Muid uilig ag tógáil cos, "},
@{ @"time":[NSNumber numberWithInt:3889],
@"line": @"Muid ag déanamh fead ghlaice, "},
@{ @"time": [NSNumber numberWithInt:4401],
@"line": @"Muid uilig ag geaibíneacht. "},
@{ @"time":[NSNumber numberWithInt:4900],
@"line": @"Buail do ghlúine 1, 2, 3, "},
@{ @"time":[NSNumber numberWithInt:5383],
@"line": @"Buail do bholg mór buí, "},
@{ @"time" :[NSNumber numberWithInt:5910],
@"line": @"Léim suas, ansin suigh síos, "},
@{ @"time": [NSNumber numberWithInt:6435],
@"line": @"Seasaigh suas go hard arís. "},
@{ @"time":[NSNumber numberWithInt:6942],
@"line": @"Sín amach do dhá lamh, "},
@{ @"time": [NSNumber numberWithInt:7430],
@"line": @"Anois lig ort go bhfuil tú ' snámh. "},
@{ @"time": [NSNumber numberWithInt:7934],
@"line": @"Amharc ar dheis, ansin ar chlé, "},
@{ @"time":[NSNumber numberWithInt:8436],
@"line": @"Tóg do shúile go dtí an spéir. "},
@{ @"time": [NSNumber numberWithInt:8940],
@"line": @"Tiontaigh thart is thart arís, "},
@{ @"time": [NSNumber numberWithInt:9436],
@"line": @"Cuir síos do dhá lámh le do thaobh, "},
@{ @"time": [NSNumber numberWithInt:9942],
@"line": @"Lámha suas is lúb do ghlúin, "},
@{ @"time": [NSNumber numberWithInt:10456],
@"line": @"Suigí síos anois go ciúin. "},
];
我正在像这样迭代数组:
[player addPeriodicTimeObserverForInterval:CMTimeMake(1, 1) queue:NULL usingBlock:^(CMTime time){
NSTimeInterval seconds = CMTimeGetSeconds(time);
for (NSObject *item in bualadhBos) {
NSLog(@"Seconds: %qi", seconds);
NSLog(@"item: %qi", [item valueForKey:@"time"]);
}
我从这里收到的输出是这样的:
2014-09-23 21:43:03.485 IciApp[1001:239870] item: 1683166570951200528
2014-09-23 21:43:03.486 IciApp[1001:239870] Seconds: 4617316992953529383
2014-09-23 21:43:03.486 IciApp[1001:239870] item: 1683489071455597664
2014-09-23 21:43:03.487 IciApp[1001:239870] Seconds: 4617316992953529383
2014-09-23 21:43:03.488 IciApp[1001:239870] item: 1683292602471563696
2014-09-23 21:43:03.488 IciApp[1001:239870] Seconds: 4617316992953529383
我不确定为什么项目行没有打印出数组中的值?还是它,我只是不明白它转换数字的方式?在我看来,它打印的是对象的 ID,而不是时间的值。我希望看到 2875 打印为项目的第一个值。
我也对 Seconds 值感到困惑。它是以毫秒为单位的值吗?
非常感谢
【问题讨论】:
标签: ios nsarray nsobject nstimeinterval