0

I am having difficulty understanding how to access values within Arrays using Objective-C My Array looks like this:

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

And I'm iterating over the array like so:

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

The Output that I receive from this is like this:

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

I'm not sure why The item lines are not printing out the values that are in the array? Or is it, and I just don't understand the way it's converted the number? It looks to me like it is printing out the id of the object and not the value of time. I am hoping to see 2875 printed as the first value for item.

Also I'm pretty confused by the Seconds value as well. Is it the value in milliseconds?

Many thanks

Linda Keating
  • 2,215
  • 7
  • 31
  • 63

1 Answers1

1

You are logging the NSNumber pointer as a long long. Try this:

for (NSDictionary *item in bualadhBos) {
    NSLog(@"Seconds: %f", seconds);
    NSNumber *time = item[@"time"];
    NSLog(@"time: %qi", [time longLongValue]);
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579