在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
创建单例的步骤: #import "Singleton.h" @implementation Singleton static Singleton *sharedSingleton = nil; + (Singleton *)sharedInstance { if (sharedSingleton == nil) { sharedSingleton = [[super allocWithZone:NULL] init]; } return sharedSingleton; } + (id)allocWithZone:(NSZone *)zone { return [[self sharedInstance] retain]; } - (id)copyWithZone:(NSZone *)zone { return self; } - (id) retain { return self; } - (NSUInteger) retainCount { return NSUIntegerMax; } - (void)release { } - (id) autorelease { return self; } @end
|
请发表评论