Skip to content

Instantly share code, notes, and snippets.

@nickynick
Last active December 27, 2015 11:48
Show Gist options
  • Save nickynick/7320756 to your computer and use it in GitHub Desktop.
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 :)
#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