Skip to content

Instantly share code, notes, and snippets.

@dwineman
Created August 7, 2014 18:52
Show Gist options
  • Save dwineman/b3df641e1fc8efa2f1ec to your computer and use it in GitHub Desktop.
Save dwineman/b3df641e1fc8efa2f1ec to your computer and use it in GitHub Desktop.
Shorthand for declaring "abstract" methods in ObjC
// Abstract.h
static inline NSException *UnimplementedMethodException(SEL cmd, Class klass) {
NSString *reason =
[NSString stringWithFormat:@"Implementation missing for abstract method: %@; class: %@",
NSStringFromSelector(cmd), NSStringFromClass(klass)];
return [NSException exceptionWithName:NSInternalInconsistencyException
reason:reason
userInfo:nil];
}
#define ABSTRACT_UNIMPLEMENTED @throw UnimplementedMethodException(_cmd, [self class]);
// MyBaseClass.m
#import "Abstract.h"
@implementation MyBaseClass
- (void)abstractMethod { ABSTRACT_UNIMPLEMENTED }
- (void)anotherAbstractMethod { ABSTRACT_UNIMPLEMENTED }
// etc.
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment