Created
October 3, 2013 01:37
-
-
Save kongtomorrow/6803313 to your computer and use it in GitHub Desktop.
compile-time generation of compile-time checked KVC key paths
This file contains hidden or 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
#import <Foundation/Foundation.h> | |
#define KVCKeyPath_1(a) @"" a | |
#define KVCKeyPath_2(a, ...) a @"." KVCKeyPath_1(__VA_ARGS__) | |
#define KVCKeyPath_3(a, ...) a @"." KVCKeyPath_2(__VA_ARGS__) | |
#define KVCKeyPath_4(a, ...) a @"." KVCKeyPath_3(__VA_ARGS__) | |
#define KVCKeyPath_5(a, ...) a @"." KVCKeyPath_4(__VA_ARGS__) | |
#define KVCKeyPath_6(a, ...) a @"." KVCKeyPath_5(__VA_ARGS__) | |
#define KVCKeyPath_7(a, ...) a @"." KVCKeyPath_6(__VA_ARGS__) | |
#define KVCKeyPath_8(a, ...) a @"." KVCKeyPath_7(__VA_ARGS__) | |
#define KVCKeyPath_9(a, ...) a @"." KVCKeyPath_8(__VA_ARGS__) | |
#define KVCKeyPath_10(a, ...) a @"." KVCKeyPath_9(__VA_ARGS__) | |
#define KVCKeyPath_11(a, ...) a @"." KVCKeyPath_10(__VA_ARGS__) | |
#define KVCKeyPath_12(a, ...) a @"." KVCKeyPath_11(__VA_ARGS__) | |
#define KVCKeyPath_13(a, ...) a @"." KVCKeyPath_12(__VA_ARGS__) | |
#define KVCKeyPath_14(a, ...) a @"." KVCKeyPath_13(__VA_ARGS__) | |
#define KVCKeyPath_15(a, ...) a @"." KVCKeyPath_14(__VA_ARGS__) | |
#define KVCKeyPath_16(a, ...) a @"." KVCKeyPath_15(__VA_ARGS__) | |
#define KVC_NUM_ARGS(...) KVC_NUM_ARGS_IMPL(__VA_ARGS__,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1) | |
#define KVC_NUM_ARGS_IMPL(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,N,...) N | |
#define KVCKeyPath_Helper_2(N, ...) (KVCKeyPath_ ## N(__VA_ARGS__)) | |
#define KVCKeyPath_Helper_1(N, ...) KVCKeyPath_Helper_2(N, __VA_ARGS__) | |
#define KVCKeyPath(...) KVCKeyPath_Helper_1(KVC_NUM_ARGS(__VA_ARGS__), __VA_ARGS__) | |
#define FooKey @"foo" | |
#define BarKey @"bar" | |
#define BazKey @"baz" | |
int main(int argc, const char * argv[]) | |
{ | |
NSLog(KVCKeyPath(FooKey, BarKey, BazKey)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment