Skip to content

Instantly share code, notes, and snippets.

@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
@implementation MySingleton
@EugeneRash
EugeneRash / objective-c init
Last active January 3, 2016 05:49
Better Objective-C init method
- (instancetype)init {
self = [super init];
if (self) {
// ...
}
return self;
}
NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1];
NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"];
NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString componentsSeparatedByCharactersInSet:separatorSet]];
[array removeObject:@""];
NSLog(@"Stack = %@", [array objectAtIndex:0]);
NSLog(@"Framework = %@", [array objectAtIndex:1]);
NSLog(@"Memory address = %@", [array objectAtIndex:2]);
NSLog(@"Class caller = %@", [array objectAtIndex:3]);
find . -name \*.m | xargs genstrings -o en.lproj

Keybase proof

I hereby claim:

  • I am eugenerash on github.
  • I am eugenegolub (https://keybase.io/eugenegolub) on keybase.
  • I have a public key ASD6rPVPCog6GnVlOagYV8QHHk-i-fhP-YM9WASdSUMQxAo

To claim this, I am signing this object: