Last active
October 7, 2015 07:07
-
-
Save elmoswelt/3124322 to your computer and use it in GitHub Desktop.
Logging and assertion macros
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
Source: http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/ | |
// Logging | |
#ifdef DEBUG | |
#define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__]) | |
#define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__] | |
#else | |
#define DLog(...) do { } while (0) | |
#ifndef NS_BLOCK_ASSERTIONS | |
#define NS_BLOCK_ASSERTIONS | |
#endif | |
#define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__]) | |
#endif | |
// Assertions | |
#define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0) | |
// Time meassurement | |
#define TICK NSDate *startTime = [NSDate date] | |
#define TOCK NSLog(@"Elapsed Time: %f", -[startTime timeIntervalSinceNow]) | |
/** Weak/Strong */ | |
#define WEAKIFY(var) \ | |
__weak typeof(var) weakVar = var; | |
#define STRONGIFY(var) \ | |
__strong typeof(var) var = weakVar; \ | |
if (var == nil) return; | |
#define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment