Skip to content

Instantly share code, notes, and snippets.

Created January 8, 2013 07:46
What would you like to do?
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)
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