Skip to content

Instantly share code, notes, and snippets.

@dwineman
dwineman / gist:b3df641e1fc8efa2f1ec
Created August 7, 2014 18:52
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];
}
@dwineman
dwineman / unscoped-method-calls
Last active January 8, 2016 12:02
Swift allows you to call instance methods from other instance methods with no scope prefix, indistinguishably from function calls. This leads to the dangerous situation of function calls being shadowed when identically-named instance methods are added to a base class.
// Derived class contains an instance method that calls a function foo() in its scope.
class Base {}
func foo() -> String {
return "function foo()"
}
class Derived: Base {
func bar() -> String {
@dwineman
dwineman / gist:6160121
Last active December 20, 2015 16:18
Magic for your main.m to force exception logging.
static void uncaughtExceptionHandler(NSException *exception) {
NSLog(@"EXCEPTION: %@", exception);
NSLog(@"Stack trace: %@", [exception callStackSymbols]);
}
int main(int argc, char *argv[]) {
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));
}