美文网首页
代码快写

代码快写

作者: WSWshallwe | 来源:发表于2019-04-22 11:32 被阅读0次

单例 定义宏

#define DJ_SINGLETON_DEF(_type_) + (_type_ *)sharedInstance;\

+(instancetype) alloc __attribute__((unavailable("call sharedInstance instead")));\

+(instancetype) new __attribute__((unavailable("call sharedInstance instead")));\

-(instancetype) copy __attribute__((unavailable("call sharedInstance instead")));\

-(instancetype) mutableCopy __attribute__((unavailable("call sharedInstance instead")));\

#define DJ_SINGLETON_IMP(_type_) + (_type_ *)sharedInstance{\

static _type_ *theSharedInstance = nil;\

static dispatch_once_t onceToken;\

dispatch_once(&onceToken, ^{\

theSharedInstance = [[super alloc] init];\

});\

return theSharedInstance;\

}

定义和实现:

@interface DJSingleton : NSObject

    DJ_SINGLETON_DEF(DJSingleton);

@end

@implementation DJSingleton

    DJ_SINGLETON_IMP(DJSingleton);

@end

相关文章

  • 代码快写

    单例 定义宏 #defineDJ_SINGLETON_DEF(_type_)+(_type_*)sharedIns...

  • 开智学堂02《快写慢改写作训练营》课程笔记·思维导图02【Ch1

    开智学堂《快写慢改写作训练营》课程笔记·思维导图02【Ch1快写慢改方法论】 Ch1快写慢改方法论 开智学堂《快写...

  • 如何快速写作论文初稿?

    注意顺序,善用工具,快写慢改。 原则 高效论文写作,遵循两个法则: 快写; 慢改。 “快写”就是快速起草。用最短的...

  • 快写吧

    又到了11点,不睡,我害怕明天工作的时候又打盹,睡吧,对不起自己更文的目标。 快写吧,别磨蹭了。 今天速写600字...

  • HTML快写

  • 快写吐了

    最近一段时间,上级要求写的文件材料数不胜数,而且还都所谓的急件,哪怕加班加点也要赶出来的那种。 五年来,针对某某内...

  • 快写啊

    高中的作业总是铺天盖地的,特别到了晚自习,各科课代表都纷纷找上门来检查作业。 “你快写啊,彭东凤都快到了。”郑鹏一...

  • webstorm快捷键和常用方法

    webstorm快捷键和常用方法 这些都是肯定要用到的,尤其分号之前的快捷键建议多看多用加快写代码效率 shift...

  • 快写完作业了

    不知道大家快写完作业是什么样的感觉吧?反正我就觉得我快写完作业的感觉就是特别特别的爽! 在快写完作业...

  • 日更主题:快写我、快写我

    今天又不知道写什么了,拿着手机,好纠结。 在我百思不得其解的时候,周某人跑过来说:“快写我、快写我,比如我今天辉煌...

网友评论

      本文标题:代码快写

      本文链接:https://www.haomeiwen.com/subject/lrqygqtx.html