一、单例(ARC)
3,copy
ThemeManger *tm = [ThemeManger shareManger];
[tm copy];//复制一个同样的对象,单例里面不允许这样
mutableCopy复制副本是可变的
(MRC)单例,需要重写以下四个方法
防止创建一个对象之后,MRC环境下会手动管理内存,调用relese活autorelese方法,单例情况下不让对象销毁,我们重写relese方法与autorelese方法(什么事情都不做)
完整code:
static
ViewController
*Vc = nil;
+ (ViewController
*) defaultShare{
static
dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Vc
= [[ViewController
alloc]
init];
});
return
Vc;
}
+ (id) allocWithZone:(struct
_NSZone
*)zone{
if
(zone==nil) {
Vc
= [super
allocWithZone:zone];
return
Vc;
}
return
nil;
}
+ (id) copyWithZone:(struct
_NSZone
*)zone{
if
(zone == nil) {
Vc
= [super
copyWithZone:zone];
return
Vc;
}
return
nil;
}
+ (id) mutableCopyWithZone:(struct
_NSZone
*)zone{
if
(zone == nil) {
Vc
= [super
mutableCopyWithZone:zone];
return
Vc;
}
return
nil;
}

223

被折叠的 条评论
为什么被折叠?



