Created
March 12, 2014 18:37
-
-
Save paulrehkugler/9513455 to your computer and use it in GitHub Desktop.
Macro fails when NSArray literals (i.e. @[]) aren't wrapped in parentheses (i.e. (@[])).
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
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 | |
#define IOS7_CODE_WITH_FALLBACK(iOS7_code, other_code) \ | |
do { \ | |
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {\ | |
iOS7_code \ | |
}\ | |
else { \ | |
other_code \ | |
} \ | |
} \ | |
while(false) | |
#define IOS7_CODE(code) \ | |
IOS7_CODE_WITH_FALLBACK(code, ;); | |
#endif | |
#ifndef IOS7_CODE | |
#define IOS7_CODE(code) do {} while(false) | |
#endif | |
#ifndef IOS7_CODE_WITH_FALLBACK | |
#define IOS7_CODE_WITH_FALLBACK(iOS7_code, other_code) \ | |
do { \ | |
other_code \ | |
}\ | |
while(false) | |
#endif | |
- (void) brokenMethod { | |
// Use of undeclared identifier 'IOS7_CODE' | |
// Too many arguments provided to function-like macro invocation | |
IOS7_CODE({ | |
// no parens around NSArray literal | |
NSArray *someArray = @[]; | |
}); | |
} | |
- (void) workingMethod { | |
IOS7_CODE({ | |
// parens around NSArray literal | |
NSArray *someArray = (@[]); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment