【发布时间】:2015-03-04 07:12:05
【问题描述】:
我创建了一个单例:
+(instancetype)allocWithZone:(struct _NSZone *)zone
{
NSAssert(FALSE, @"Please use getSharedInstance class method of MotionManager to avoid singleton abuse. =)");
return nil;
}
+ (id) getSharedInstance
{
if (!instance)
{
instance = [[super allocWithZone:NULL] init];
}
return instance;
}
为什么上面的工作正常,但下面的抛出异常?
+(instancetype)allocWithZone:(struct _NSZone *)zone
{
NSAssert(FALSE, @"Please use getSharedInstance class method of MotionManager to avoid singleton abuse. =)");
return nil;
}
+ (id) getSharedInstance
{
if (!instance)
{
instance = [[super alloc] init];
}
return instance;
}
【问题讨论】:
标签: ios objective-c singleton