Skip to content

Instantly share code, notes, and snippets.

@nevyn
Last active May 12, 2016 01:08
Show Gist options
  • Save nevyn/da531742d1aec55fb785fd27c287db86 to your computer and use it in GitHub Desktop.
Save nevyn/da531742d1aec55fb785fd27c287db86 to your computer and use it in GitHub Desktop.
#define LBGuard(cond, ...) \
BOOL __COND_SUCCESSFUL_AT ## __LINE__ = (cond); \
if(!__COND_SUCCESSFUL_AT ## __LINE__) {\
NSString *failureReason = [NSString stringWithFormat:__VA_ARGS__]; \
NSAssert(NO, @"Guard failed: %@: %@", @#cond, failureReason); \
NSLog(@"Guard failed: %@: %@", @#cond, failureReason);\
} \
if(__COND_SUCCESSFUL_AT ## __LINE__) {}
// Usage:
LBGuard([fluxCapacitor isCharged]) else {
*error = [NSError fluxError];
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment