Created
August 7, 2014 18:52
-
-
Save dwineman/b3df641e1fc8efa2f1ec to your computer and use it in GitHub Desktop.
Shorthand for declaring "abstract" methods in ObjC
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 characters
// 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