Skip to content

Instantly share code, notes, and snippets.

@quinntaylor
quinntaylor / CompilerCheckedKeyPaths.h
Created November 13, 2014 06:14
Code for getting compiler check on key paths, more accurate than using NSStringFromSelector(@selector(foo)).
// See http://nshipster.com/key-value-observing/
// Put this code a common utilities header, and use it to have the compiler help check correctness of key paths.
// Uses macro stringification to create an Obj-C string literal, plus validation code that the compiler optimizes out.
@interface NSObject (KeyPathFakeCategoryForCompilerWarnings)
+ (instancetype)__fake_method_for_compiler_warnings__;
- (instancetype)__fake_method_for_compiler_warnings__;
@end
/*! Returns a string for the given keypath, but causes a compiler warning if the keypath is not defined on \c self.