zoukankan      html  css  js  c++  java
  • iOS开发中常用的单例

    定义:一个类的对象,无论在何时创建、无论创建多少次,创建出来的对象都是同一个对象。
    使用场景:当有一些数据需要共享给别的类的时候,就可以把这些数据保存在单例对象中。
     
    关键代码
    + (instancetype)allocWithZone:(struct_NSZone *)zone
    {
        static id instance = nil;
        if(instance == nil)
        {
          instance =   [super allocWithZone:zone];
        }
        return instance;
    }

    1、UIApplication(应用程序实例)

    获取方式:[UIApplication sharedApplication]

    详细:http://www.cnblogs.com/hissia/p/5678518.html

    2、NSNotificationCenter(消息中心)

    获取方式:[NSNotificationCenter defaultCenter]

    常用的通知模式

    3、NSFileManager(文件管理)

    获取方式:[NSFileManager defaultManager]

    4、NSUserDefaults(偏好设置)

    获取方式:[NSUserDefaults standardUserDefaults]

    详细:http://www.cnblogs.com/hissia/p/5642405.html

    5、NSURLCache(请求缓存)

    获取方式:[NSURLCache sharedURLCache]

    6、NSHTTPCookieStorage(应用程序cookies池)

    获取方式:[NSHTTPCookieStorage sharedHTTPCookieStorage]

    7、NSURLSession(发送请求时候用的)                

    获取方式:[NSURLSession sharedSession]

    8、UIMenuController(弹出的菜单可以选择,复制,剪切,粘贴的功能)      

    获取方式:[UIMenuController sharedMenuController]

    详细:http://www.cnblogs.com/hissia/p/5668513.html

  • 相关阅读:
    MySQL显示数据库版本的SQL语句
    如何清空ostringstream对象中的内容
    C/C++中的Split函数
    关于socket长连接的心跳包
    利用MyEclipse配置S2SH三大框架篇-Spring配置
    利用MyEclipse配置S2SH三大框架篇-struts2配置
    Oracle OCP 11G 051答案解析目录
    AFX_EXT_CLASS
    C++中的explicit关键字
    SSH2三大框架整合警告
  • 原文地址:https://www.cnblogs.com/panda1024/p/5734411.html
Copyright © 2011-2022 走看看