object-c单例很好用,赶紧记下来

单例

                                                                       -EnGirl开发经验分享


.h文件

@interfaceCommonProperties :NSObject

+(CommonProperties*)shareProperties;

.m文件

#import"CommonProperties.h"

@implementationCommonProperties

staticCommonProperties*commonProperties =nil;

+ (CommonProperties*)shareProperties

{

staticdispatch_once_tonceToken;

dispatch_once(&onceToken, ^{

commonProperties= [[superallocWithZone:NULL]init];

});

returncommonProperties;

}

+ (id)allocWithZone:(struct_NSZone*)zone

{

return[CommonPropertiesshareProperties];

}

- (id)init

{

self= [superinit];

if(self) {


}

return self;

}

@end

你可能感兴趣的:(object-c单例很好用,赶紧记下来)