I'm a newbie to Objective-C, so please bear with me.
I have a custom object called UpdateData:
@interface UpdateData : NSObject
-(NSString*) getPath;
-(void) setPath:(NSString*) path ;
@end
As I create this items from parsing a list:
NSMutableArray *serverData = [[NSMutableArray alloc]init];
for (i = 1; i < [chunks count]; i++) {//chunks contains infor for parsing
UpdateData *ud = [[UpdateData alloc] init];
NSString * element = [chunks objectAtIndex:i];
[ud setPath: element];
[serverData addObject:ud];
NSLog(@"Path: %@",[[serverData lastObject] getPath]);
}
NSLog(@"Done parsing! Elements: %lu", [serverData count]);
Within that loop, the UpdateData (read straight from the Array) have the values. I get the following output:
Path: path
.
.
.
Done parsing! Elements: x
Where x is greater than 0 and equal to the objects parsed and path is the correct path parsed.
In the same method I later try to go over the Array to read the values of the objects:
for (i = 0; i < [serverData count]; i++) {
UpdateData *ud = [serverData objectAtIndex:i];
NSLog(@"Path: %@",[ud getPath]);
}
There the output is:
Path:
Values are lost. The for loops are back to back, exactly as shown above.
Any ideas?
Update:
The UpdateData class:
#import "UpdateData.h"
@implementation UpdateData
NSString* path=@"";
-(NSString*) getPath{
return path;
}
-(void) setPath:(NSString*) newpath{
path = newpath;
}
@end
Does that initialization there matter? Should be overwritten right?
getPathdoing? By the way: Getters in Objecive-C don't begin with 'get'.