2014-09-23 4 views
0
나는 내 배열은 다음과 같습니다 목표 - C 사용하여 배열에서 값에 액세스하는 방법을 이해하는 어려움을 겪고

:액세스 IOS 배열에 포함 된 값과 사전

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. "}, 
       ]; 

그리고 내가 지금과 같은 배열을 반복하고 있습니다를 :

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 
,536,913,632 :

[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"]);     
     } 

나는이에서받은 출력이 같다 10

왜 항목 라인이 배열에있는 값을 인쇄하지 않는지 잘 모르겠습니다. 또는 그것이 무엇입니까, 그리고 그것은 숫자를 변환하는 방법을 이해하지 못합니까? 그것은 나에게 시간의 가치가 아니라 객체의 ID를 인쇄하는 것처럼 보입니다. 나는 항목의 첫 번째 값으로 2875가 인쇄되기를 기대하고있다.

또한 Seconds 값도 꽤 혼란 스럽습니다. 밀리 초 단위의 값입니까?

많은 감사

답변

1

당신은 long long으로 NSNumber 포인터를 기록하고 있습니다. 이것을 시도하십시오 :

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

감사합니다 - 저에게 많은 도움이되었습니다. 초가 지금 무엇인지 파악할 필요가 있습니다. 매우 큰 숫자라는 것이 매우 혼란 스럽습니다. –

+0

방금 ​​내 대답을 업데이트했습니다. 'seconds '가 기록되는 방식을 변경합니다. 'NSTimeInterval'은'long long'이 아니라'double'입니다. 도움이되는지 확인하십시오. – rmaddy

+0

은 더 많은 감사를드립니다. Objective-C에서 많은 것을 배웠습니다. –