2014-09-23 83 views
0

我有困難瞭解如何使用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的價值。它是以毫秒爲單位的值嗎?

非常感謝

回答

1

要記錄NSNumber指針作爲long long。試試這個:

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

謝謝 - 這幫了我很多。只需要弄清楚現在秒是什麼。非常困惑,這是一個很大的數字。 – 2014-09-23 21:05:42

+0

我剛剛更新了我的答案。我改變'秒'的記錄方式。 'NSTimeInterval'是一個'雙',而不是'long long'。看看是否有幫助。 – rmaddy 2014-09-23 21:09:53

+0

,這使得更多的意義感謝。在Objective-C中我有很多東西需要學習 – 2014-09-23 21:16:09