0

I'm integrating the BEMSimpleLineGraph library into my Objective-C iPhone app, and I'm having trouble adding int values from my Core Data to an NSMutableArray, and later retrieving the values in the same class but a different method.

Here is the code I use to fill the array:

// Get those points from Core Data into my arrays
for (int i = 0; i < countInArray; i++) {

    NSManagedObject *device = [self.tapTestsConducted objectAtIndex:i];

    int leftInt, rightInt;

    leftInt = [[device valueForKey:@"leftNumber"] intValue];
    rightInt = [[device valueForKey:@"rightNumber"] intValue];

    [_leftArray addObject: [NSNumber numberWithInt:leftInt]];
    [_rightArray addObject: [NSNumber numberWithInt:rightInt]];

    NSDate *date = [device valueForKey:@"date"];
    [self.dateArray addObject: date];

    // For testing - Did the correct data get into the arrays?

    NSLog(@"%d", leftInt);
    NSLog(@"%d", rightInt);
    NSLog(@"%@", date);
}

Here is the method used to find the graph's y values:

- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSInteger)index {
NSNumber *anumber = [_leftArray objectAtIndex:index];
int anInt = [anumber intValue];

NSLog(@"%d", anInt);
return anInt;
}

The NSLog in the first part outputs the correct data, but the NSLog in the second method outputs all 0.

Any advice or input is greatly appreciated!

EDIT: here is the NSLog output at a runtime:

2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 5 tests conducted
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 12
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 0
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 2016-08-31 23:49:12 +0000
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 20
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 0
2016-09-11 22:30:04.072 CNS Test CD[16805:849994] 2016-09-02 23:31:44 +0000
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 0
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 17
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 2016-09-02 23:32:12 +0000
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 12
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 0
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 2016-09-05 19:13:19 +0000
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 13
2016-09-11 22:30:04.073 CNS Test CD[16805:849994] 0
2016-09-11 22:30:04.074 CNS Test CD[16805:849994] 2016-09-05 19:13:55 +0000
2016-09-11 22:30:05.949 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.950 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.951 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.955 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.955 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.955 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.956 CNS Test CD[16805:849994] 0
2016-09-11 22:30:05.956 CNS Test CD[16805:849994] 0
Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
MacNick
  • 24
  • 7

1 Answers1

0

I had properly declared my NSMutableArrays in my .h file as so:

@property (strong, nonatomic) NSMutableArray *leftArray;
@property (strong, nonatomic) NSMutableArray *rightArray;
@property (strong, nonatomic) NSMutableArray *dateArray;

What I had not done, and which fixed the issue after I did it, was to initialize my arras with an alloc init. I placed these lines before the for loop.

self.leftArray = [[NSMutableArray alloc] init];
self.rightArray = [[NSMutableArray alloc] init];
self.dateArray = [[NSMutableArray alloc] init];
MacNick
  • 24
  • 7