【发布时间】:2013-01-12 01:25:05
【问题描述】:
#import "ApiService.h"
@implementation ApiService
static ApiService *sharedInstance = nil;
+ (ApiService *)sharedInstance
{
if (sharedInstance == nil)
{
sharedInstance = [[self alloc]init];
}
return sharedInstance;
}
- (id)init
{
if (self = [super init])
{
}
return self;
}
@end
当我打电话给+sharedInstance 时,self 指的是什么?如何允许从 Class 方法调用 init?
【问题讨论】:
-
查看这个问题以获得更好的单例制作方法:stackoverflow.com/questions/5720029/…
标签: objective-c singleton