Skip to content

Instantly share code, notes, and snippets.

@darknoon
Created January 8, 2013 07:46
Show Gist options
  • Save darknoon/4482025 to your computer and use it in GitHub Desktop.
Save darknoon/4482025 to your computer and use it in GitHub Desktop.
Safe KVC macro by Andrew Pouliot. In the public domain.
//o is an object type, k is the key on which to check validity
//returns a NSString constant of the relevant key
#define KVC(o, k) (0 && sizeof(o.k) ? @#k : @#k)
//Usage:
ObjectWithMethodCalledKeyName *object = ...;
[object addObserver:self forKeyPath:KVC(object, keyName) options:0 context:NULL];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment