小编mel*_*nye的帖子

为什么为单例的静态变量赋值为nil

使用它有什么好处:

+ (CardPainter*) sharedPainter {
    static CardPainter* sp = nil;

    if (nil == sp) {
        sp = [[CardPainter alloc] init];
    }

    return sp;
}
Run Code Online (Sandbox Code Playgroud)

而不是这个:

+ (CardPainter*) sharedPainter {
    static CardPainter* sp = [[CardPainter alloc] init];

    return sp;
}
Run Code Online (Sandbox Code Playgroud)

静态变量初始化只执行一次,所以我看不到前者的优点.

null singleton static objective-c

5
推荐指数
1
解决办法
452
查看次数

标签 统计

null ×1

objective-c ×1

singleton ×1

static ×1