Skip to content

Instantly share code, notes, and snippets.

@ashfurrow
Created January 28, 2015 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashfurrow/bbb04f8272c2f32d5bb7 to your computer and use it in GitHub Desktop.
Save ashfurrow/bbb04f8272c2f32d5bb7 to your computer and use it in GitHub Desktop.
Never-null combined assertion/assignment macro
// From https://twitter.com/tewha/status/560497711397355520
#define NEVER_NULL(a, desc, ...) ({\
do {\
__PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS\
if ((a) == nil) {\
[[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd\
object:self file:[NSString stringWithUTF8String:__FILE__]\
lineNumber:__LINE__ description:(desc), ##__VA_ARGS__];\
}\
__PRAGMA_POP_NO_EXTRA_ARG_WARNINGS\
} while(0);\
(a);\
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment