Skip to content

Instantly share code, notes, and snippets.

@shaps80
Created January 22, 2014 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaps80/8562258 to your computer and use it in GitHub Desktop.
Save shaps80/8562258 to your computer and use it in GitHub Desktop.
ProTip: Better way to raise an exception when -init is called on a class that implements a designated initialiser. Turn on -Wstrict-selector-match to get compiler warnings when this selector doesn't exist. Some IDEs (like AppCode) will even refactor this for you should you change the selector ;) The best thing about this is if its inside a stati…
- (instancetype)init
{
SEL selector = @selector(initWithName:);
[NSException raise:NSGenericException format:@"Please use %@", NSStringFromSelector(selector)];
return nil;
}
- (instancetype)initWithName:(NSString *)name
{
self = [super init];
if (self) {
_name = name;
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment