当前位置: 首页 > news >正文

建设网上银行app下载安装搜索引擎优化核心

建设网上银行app下载安装,搜索引擎优化核心,个人网页制作 个人主页,风烛源网站管理系统iOS单例初步理解 在iOS开发中#xff0c;系统自带的框架中使用了很多单例#xff0c;非常方便用户#xff08;开发者#xff0c;使用比如[NSApplication sharedApplication] 等#xff09;#xff0c;在实际的开发中#xff0c;有时候也需要设计单例对象#xff0c;为…iOS单例初步理解 在iOS开发中系统自带的框架中使用了很多单例非常方便用户开发者使用比如[NSApplication sharedApplication] 等在实际的开发中有时候也需要设计单例对象为保证每次获取的对象都为同一个对象。 在iOS开发中创建单例具体步骤 1.提供一个类方法 (instancetype)sharedXXXX; 2.创建一个全局静态变量static id _instance; 3.重写allocWithZone 4.重写copyWithZone 特举例子如下 interface MusicTool : NSObject (instancetype)sharedMusicTool; end static id _instance; // 全局变量 /** * alloc方法内部会调用allocWithZone */ (id)allocWithZone:(struct _NSZone *)zone { if (_instance nil) { synchronized(self) { if (_instance nil) { _instance [super allocWithZone:zone]; } } } return _instance; } /** * 重写copy方法防止copy出错 */ - (instancetype)copyWithZone:(NSZone *)zone { return _instance; } (instancetype)sharedMusicTool { if (_instance nil) { synchronized(self) { if (_instance nil) { _instance [[self alloc] init]; } } } return _instance; } 第二种使用GCD创建单例方法 interface DataTool : NSObject (instancetype)shareDataTool; end static id _instance; (id)allocWithZone:(struct _NSZone *)zone { if (_instance nil) { static dispatch_once_t onceToken; dispatch_once(onceToken, ^{ _instance [super allocWithZone:zone]; }); } return _instance; } - (instancetype)copyWithZone:(NSZone *)zone { return _instance; } (instancetype)shareDataTool { if (_instance nil) { static dispatch_once_t onceToken; dispatch_once(onceToken, ^{ _instance [[self alloc]init]; }); } return _instance; } 第三种使用饿汉模式 interface SoundTool : NSObject (instancetype)sharedSoundTool; end static id _instance; (void)load { _instance [[self alloc]init]; } (instancetype)allocWithZone:(struct _NSZone *)zone { if (_instance nil) { _instance [super allocWithZone:zone]; } return _instance; }(instancetype)sharedSoundTool { return _instance; }(instancetype)copyWithZone:(NSZone *)zone { return _instance; } 为保证兼容MRC还需要重写 static id _instace; (id)allocWithZone:(struct _NSZone *)zone { static dispatch_once_t onceToken; dispatch_once(onceToken, ^{ _instace [super allocWithZone:zone]; }); return _instace; }(instancetype)sharedDataTool { static dispatch_once_t onceToken; dispatch_once(onceToken, ^{ _instace [[self alloc] init]; }); return _instace; }(id)copyWithZone:(NSZone *)zone { return _instace; }(oneway void)release { } //重写release(id)retain { return self; } //重写retain(NSUInteger)retainCount { return 1;} //重写retainCount(id)autorelease { return self;} //重写autorelease
http://www.zqtcl.cn/news/478545/

相关文章:

  • 邢台营销型网站建设做网站的保证承诺
  • 关于茶叶的网站模板免费下载wordpress多边形按钮
  • 贵阳市网站建设手工制作花
  • 娄底哪里做网站免费永久不限空间
  • 网站标签怎么做wordpress 后台模板
  • 内江移动网站建设网站内部链接的作用有哪些
  • 阿里云的wordpress建站wordpress 批量定时发布
  • 网站院长信箱怎么做海报设计制作网站
  • 办网站如何备案怎么制作微信链接网页
  • 聊城门户网站建设怎样能有个人网站
  • 营销网站建设资料创意网站 模板
  • 免费的短网址生成器深圳外贸网站优化
  • 网站推广哪个平台最好图库
  • 在东莞做网站vue做网站好吗
  • 手机网站的页面大小郑州恩恩网站建设
  • 视频运营管理平台长沙网站seo技术
  • 网站建设有哪些规章制度网页版面
  • 海伦网站建设做网站建设的联系电话
  • 免费做字体的网站枣强网站建设代理
  • 建设网站素材海南百度推广公司电话
  • 温州企业网站建设费用培训行业门户网站建设方案
  • 口碑好的常州网站优化深圳市光明区实验学校
  • 网站怎么做微博认证网页设计代码html作品展示
  • 在线网站建设活动初创企业的建站流程
  • 汨罗哪里有网站开发的公司电话百度首页关键词推广
  • 天津百度整站优化服务政务网站模版
  • 推荐家居企业网站建设用什么工具修改wordpress
  • wix做的网站能扒下来哈尔滨做网站的oeminc
  • 做网站的网络公司门户网站介绍
  • 软件公司网站系统集成建设下拉关键词排名