访问IOS数组和字典中包含的值

访问IOS数组和字典中包含的值,ios,nsarray,nsobject,nstimeinterval,Ios,Nsarray,Nsobject,Nstimeinterval,我很难理解如何使用Objective-C访问数组中的值 我的数组如下所示: bualadhBos = @[ @{ @"time":[NSNumber numberWithInt:2875], @"line" : @"Muid uilig ag bualadh bos, "}, @{ @"time":[NSNumber numberWithInt:3407], @"l

我很难理解如何使用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打印作为第一个项目的价值

另外,秒值也让我很困惑。它是以毫秒为单位的值吗


非常感谢

您正在将
NSNumber
指针记录为
long
。试试这个:

for (NSDictionary *item in bualadhBos) {
    NSLog(@"Seconds: %f", seconds);
    NSNumber *time = item[@"time"];
    NSLog(@"time: %qi", [time longLongValue]);
}

谢谢,这对我帮助很大。只需要弄清楚现在的秒数是多少。这么大的数字让我很困惑。我刚刚更新了我的答案。我更改
秒的记录方式
NSTimeInterval
是一个
double
,而不是
long
。看看这是否有帮助。这更有意义,谢谢。在Objective-C中我有很多东西要学