我做了很多搜索,并没有真正找到我的问题的答案所以希望有人能够指出我正确的方向
我是Objective C的新手,我有一个小问题,执行一些我认为很简单的事情; 从类方法返回NSArray对象
我有以下类与相关的类方法
@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
Run Code Online (Sandbox Code Playgroud)
我有一个带有以下代码的ViewController(为便于阅读而修剪):
@implementation RootViewController
@synthesize saleList = _saleList;
- (void)viewDidLoad {
[super viewDidLoad];
// …Run Code Online (Sandbox Code Playgroud)