码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 创建单例的方法

时间:2014-11-12 16:19:57      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:style   io   color   ar   os   sp   文件   on   bs   

在ios4之后出现了一种单例的写法:

首先创建一个继承于NSObject的类

在.h文件中声明一个类方法

+ (InstallStatisticsClass *)shareInstance;

在.m中将这个方法

+ (InstallStatisticsClass *)shareInstance

{

    static InstallStatisticsClass *instance = nil;

    static dispatch_once_t str;

    dispatch_once (&str,^{

        instance = [[super allocWithZone:nil] init];

    });

    return instance;

}

iOS 创建单例的方法

标签:style   io   color   ar   os   sp   文件   on   bs   

原文地址:http://www.cnblogs.com/anyezhuixing/p/4092454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!