乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      IOS設(shè)計模式之一:單例模式

       quasiceo 2015-03-19

      IOS設(shè)計模式之一:單例模式

      單例模式的意思就是只有一個實例。單例模式確保某一個類只有一個實例,而且自行實例化并向整個系統(tǒng)提供這個實例。這個類稱為單例類。

      復(fù)制代碼
      #import <Foundation/Foundation.h>
       
       @interface Singleton : NSObject 
       +(Singleton *) instance;
      @end @implementation Singleton
      +(Singleton *) instance { static Singleton *sharedSingleton_ = nil; @synchronized(self){ if(sharedSingleton_ == nil){ sharedSingleton_ = [NSAllocateObject([self class], 0, 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 { [super release]; } - (id) autorelease { return self; } @end
      復(fù)制代碼

       當(dāng)然,ios 5以上啟用ARC就簡單多了:

      復(fù)制代碼
      static RootViewController* sharedRootController = nil;
       
      +(RootViewController *) sharedController{
          @synchronized(self){
              if (sharedRootController == nil) {
                 sharedRootController = [[self alloc] init];
              }
          }
          return  singleController;
      }
      復(fù)制代碼
      歡迎轉(zhuǎn)載,但請保留鏈接 http://www.cnblogs.com/limlee --- GeekLion

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多