In my iPhone app, I have added core plot.
It works fine if I randomly create values through the for
loop (commented lines in code below)
When I try passing an array of values as the plot points the app crashes.
What could be wrong?
I tried debugging but values are fetched from the array correctly. Also there is no error message in Console when the app crashes.
Below is the code where the array values are passed
Code:
- (void)generateData
{
NSArray *A = [[NSArray alloc] initWithObjects:@"1000",@"2000",@"1100",@"4000",nil];
NSArray *B = [[NSArray alloc] initWithObjects:@"1100",@"2200",@"3300",@"4400",nil];
if (plotData == nil)
{
NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:100];
for (NSUInteger i = 0; i < 4; i++)
{
id x = (NSNumber *)[NSNumber numberWithUnsignedInteger:[[A objectAtIndex:i] intValue]];
id y = (NSNumber *)[NSNumber numberWithUnsignedInteger:[[B objectAtIndex:i] intValue]];
// id x = [NSDecimalNumber numberWithDouble:1.0 + i * 0.05];
// id y = [NSDecimalNumber numberWithDouble:1.2 * rand()/(double)RAND_MAX + 0.5];
[contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
}
plotData = [contentArray retain];
}
}
Got the solution.
It was because it was treating the array values as strings so I refered to this link
iphone, using an array to define in core-plot range
and that solved my problem.
Thanks Brad Larson for your help. Keep up your good work.!!
Hope this helps someone.