Revisions
-
virasio revised this gist
Aug 4, 2014 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,13 +7,15 @@ + (instancetype) sharedInstance { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[super alloc] initInstance]; }); return sharedInstance; } - (instancetype) initInstance { self = [super init]; // Do any other initialisation stuff here // ... return self; } // ... -
virasio created this gist
Apr 2, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ @interface MySingleton : NSObject // ... + (instancetype) sharedInstance; + (instancetype) alloc __attribute__((unavailable("alloc not available, call sharedInstance instead"))); - (instancetype) init __attribute__((unavailable("init not available, call sharedInstance instead"))); + (instancetype) new __attribute__((unavailable("new not available, call sharedInstance instead"))); // ... @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ @implimentation MySingleton // ... + (instancetype) sharedInstance { static id sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[super alloc] initInstance]; // Do any other initialisation stuff here }); return sharedInstance; } - (instancetype) initInstance { return [super init]; } // ... @end