I’m trying to add values to the yArray. However in the NSLog, it always shows up null. I am synthesizing the NSMutableArray (yArray) and get no errors or warnings on compiling. I believe one reason might be that i am not initializing the array. I read somewhere that @synthesize does not initialize. However, i’m a beginner and i’m not sure how to properly initialize the array. I’ve researched it on google but couldn’t figure it out. Can someone tell me how or at least point me in the right direction. I posted a part of my code below. Thank you in advance.
for (int i = 0; i < n; ++i)
{
xx = xx + [[self.yArr1 objectAtIndex:i] doubleValue];
}
for (int i = 0; i < n; ++i)
{
if(i==0)
[self.yArray addObject:[NSNumber numberWithDouble:(0.0)]];
else
{
bb = fabs([[self.yArr1 objectAtIndex:i] doubleValue]- [[self.yArr1 objectAtIndex:(i-1)] doubleValue]);
[self.yArray addObject:[NSNumber numberWithDouble:(bb)]]; // This is the problem.
yy = yy + [[self.yArray objectAtIndex:i] doubleValue];
}
NSLog(@"prediction %f, %f, %@, %f", bb, yy, [self.yArray objectAtIndex:i],[[self.yArr1 objectAtIndex:i] doubleValue]);
}
NSLog(@"prediction %f, %f", bb, yy);
To properly initialize the array use
Initialize it before using it (maybe in
initmethod or something like that), then retry. Don’t forget to manually release it when you have done.