Skip to content

Instantly share code, notes, and snippets.

View NorrinRadd's full-sized avatar

Brandon Trussell NorrinRadd

View GitHub Profile
@NorrinRadd
NorrinRadd / gist:5664705
Created May 28, 2013 17:59
added to methods of a parent class so that subclasses are warned if they do not call super
#if __has_attribute(objc_requires_super)
#define NS_REQUIRES_SUPER __attribute((objc_requires_super))
#endif
@NorrinRadd
NorrinRadd / TestClass.h
Created May 28, 2013 17:43
Before calling an optional protocol method, it is good to check if the delegate has implemented the methods. This is usually done using the following pattern: if (_delegate && [_delegate.respondsToSelector:@selector(method1)]) { // Do your thing } Turns out that some days ago, I faced a better way to do this kind of check by creating a struct an…
// TestClass.h
#import <Foundation/Foundation.h>
@protocol TestProtocol <NSObject>
@optional
- (void) testProtocolMethod;
@end
@interface TestClass: NSObject
{
// Struct that will hold the methods that the delegate implements
#import <objc/runtime.h>
#import <objc/message.h>
#import <QuartzCore/QuartzCore.h>
#define PROPERTY(propName) NSStringFromSelector(@selector(propName))
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
#ifdef DEBUG
static void PSPDFSwizzleMethod(Class c, SEL orig, SEL new) {