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;//表示此对象不能释放
}
//下面的oneway也是多线程操作,记住
-(oneway void)release{
    //do nothing
}
-(id)autorelease
{
    return self;
}

 

相关文章:

  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2023-02-09
  • 2022-12-23
  • 2022-03-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案