Last active
December 27, 2015 11:48
-
-
Save nickynick/7320756 to your computer and use it in GitHub Desktop.
A smart macro for getting a key string for an Objective-C property. Will give you a proper compilation error if something is wrong :)
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 KEY(Class, key) ( YES ? @#key : ^{ (void)((Class *)[[Class alloc] init]).key; return @""; }() ) | |
/* | |
Usage: | |
KEY(UIViewController, navigationItem) - returns @"navigationItem" | |
KEY(UIView, frame) - returns @"frame" | |
KEY(UIView, tag) - returns @"tag" | |
KEY(UIView, foobar) - compilation error! | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment