alloc
alloc
内部只是调用了allocWithZone
方法,真正申请空间,创建对象都是allocWithZone
方法在做
实现方法:重写该类的allocWithZone
方法
+ (instancetype)allocWithZone:(struct _NSZone *)zone{
static id instance = nil;
if(instance == nil)
{
instance = [super allocWithZone:zone];
}
return instance;
}
单例模式的规范,要求提供一个类方法来返回一个单例对象
类方法的名称必须以 shared类名;default类名;
+ (instancetype)sharedPerson{
}
+ (instancetype)defaultPerson{
}