I did an honest search and did not find the answer to my question, so I was hoping that someone could point me in the right direction
I am new to Objective-C, and I have a little problem when I do something that I imagine is pretty simple; returns an NSArray of objects from a class method
I have the following class with an associated class method
@implementation Sale @synthesize title = _title; @synthesize description = _description; @synthesize date = _date; +(NSArray*)liveSales { NSArray *liveSales = [[NSArray alloc] init]; for(int i = 0; i < 100; i++) { Sale *s = [[Sale alloc] init]; [s setTitle:[NSString stringWithFormat:@"Sale %d", i+1]]; [s setDescription:[NSString stringWithFormat:@"Sale %d descriptive text", i+1]]; [liveSales addObject:s]; [s release]; s = nil; } return [liveSales autorelease]; } @end
And I have a ViewController with the following code (cropped for readability):
@implementation RootViewController @synthesize saleList = _saleList; - (void)viewDidLoad { [super viewDidLoad];
The problem I ran into is that the count of saleList is always zero, so it seems that the array is not set. If I debug the code and am in the method of the liveSales class, that is, the correct number of objects in the array at the return point
Can someone point me in the right direction?
Thanks:)
Dave
source share