Hi Im having a problem, where I'm trying to add a object to an array, when I do this, my values for that object become 0. I have yet to understand why.
Here is the bit of code.
Code:
int max = 100;
NSLog(@"%d",[[currentProblem arguments] count]);
for(int i = 0; i < [[currentProblem arguments] count]; i++) {
if([[currentProblem arguments] objectAtIndex:i] != NULL) {
PieChartData *myData = [[PieChartData alloc] init];
NSLog([[currentProblem arguments] objectAtIndex:i]);
[myData setName:[[currentProblem arguments] objectAtIndex:i]];
max = [self randomNumberWithMax:max];
[myData setValue:max];
NSLog(@"%d",max);
[diagramData addObject:myData];
NSLog([[diagramData objectAtIndex:i] name]);
NSLog(@"%d",[[diagramData objectAtIndex:i] value]);
[myData release];
}
}
____
this is my PieChartData
____ .h
Code:
@interface PieChartData : NSObject {
int value;
NSString *name;
}
@property (nonatomic, retain) NSString *name;
@property int value;
_____ .m
Code:
@implementation PieChartData
@synthesize value;
@synthesize name;
___
When I ask it to print to the log the number max it does, and its != 0 then when i ask it to print the value of the object. i get 0... HELP!
Here is an example of what my console prints:
Code:
5
America
randomNumberWithMax
49
0
Asia
randomNumberWithMax
37
0
Europe
randomNumberWithMax
12
0
Africa
randomNumberWithMax
8
0
Australia
randomNumberWithMax
4
0