Last active
September 3, 2015 12:15
-
-
Save emreberge/9c38488284c9c86b349a to your computer and use it in GitHub Desktop.
Compiler help for keyPaths!
This file contains 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
#define KeyPath(keyPath)\ | |
^NSString *(void) {\ | |
__unused __typeof__(keyPath) x;\ | |
return [@#keyPath substringFromIndex:([@#keyPath rangeOfString:@"."].location + 1)];\ | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I often find that you want to observe an object that is already a property of another object, and then this kind of breaks down. For example, this snippet does not work:
To support this case as well, we can add the NSBackwardsSearch option to the rangeOfString call.