zoukankan      html  css  js  c++  java
  • iOS单例宏

    //
    //  Single.h
    //  FKLTest
    //
    //  Created by kun on 16/8/11.
    //  Copyright © 2016年 kun. All rights reserved.
    //
    
    #ifndef Single_h
    #define Single_h
    
    #define SingelH(name) +(instancetype)share##name;
    
    #if __has_feature(objc_arc) // 条件编译 ARC
    #define SingelM(name) static id share##name = nil;
    + (instancetype)allocWithZone:(struct _NSZone *)zone
    {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
    if ( !share##name )
    {
    share##name = [super allocWithZone:zone];
    }
    });
    return share##name;
    }
    + (instancetype)share##name
    {
    return [[self alloc] init];
    }
    - (id)copyWithZone:(NSZone *)zone
    {
    return share##name;
    }
    - (id)mutableCopyWithZone:(NSZone *)zone
    {
    return share##name;
    }
    #else // 条件编译 MRC
    #define SingelM(name) static id share##name = nil;
    + (instancetype)allocWithZone:(struct _NSZone *)zone
    {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
    if ( !share##name )
    {
    share##name = [super allocWithZone:zone];
    }
    });
    return share##name;
    }
    + (instancetype)share##name
    {
    return [[self alloc] init];
    }
    - (id)copyWithZone:(NSZone *)zone
    {
    return share##name;
    }
    - (id)mutableCopyWithZone:(NSZone *)zone
    {
    return share##name;
    }
    - (oneway void)release
    {
    }
    - (instancetype)retain
    {
        return shared##name;
    }
    - (NSUInteger)retainCount
    {
        return MAXFLOAT;
    }
    #endif // 条件编译
    
    #endif /* Single_h */
  • 相关阅读:
    mysql5.6 TIME,DATETIME,TIMESTAMP
    CMake 简单介绍 图
    mysql 源码编绎修改 FLAGS,调试MYSQL
    CHAR 详解
    关于MySQL的各种总结
    Shell编程速查手册
    cmake 手册系列
    编译安装GCC 5.2.0
    宽字符相关的输入输出
    Makefile
  • 原文地址:https://www.cnblogs.com/fkunlam/p/5760485.html
Copyright © 2011-2022 走看看