Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Common Macros for Xcode projects
// Useful Macros.
// The best place to import this is in your project's pch file.
// See for details.
// Most current version at along with usage notes.
#ifndef jcscommonmacros
#define jcscommonmacros_1_0 10000
#define jcscommonmacros jcscommonmacros_1_0
#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__]
#define DLog(...) do { } while (0)
#define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0)
A convenience function that provides a general test for emptiness
Courtesy of Wil Shipley
@param thing An object to test for emptiness
@return YES if the object is empty, NO otherwise
static inline BOOL isEmpty(id thing) {
return thing == nil
|| ([thing respondsToSelector:@selector(length)]
&& [(NSData *)thing length] == 0)
|| ([thing respondsToSelector:@selector(count)]
&& [(NSArray *)thing count] == 0);
A convenience function for logging BOOL variables
@param value the variable for logging
@return YES or NO
static inline NSString *boolString(BOOL value) {
return value ? @"YES" : @"NO";

This comment has been minimized.

Copy link
Owner Author

@Abizern Abizern commented May 6, 2010


I don't use this anymore as it's not valid for Swift

These are standard additions to my .pch file for Xcode projects. Most of my open source code requires them.

import this header into your project's pch file after all the imports.

See the Cocoa is my Girlfriend post on using the macros:

Also, Wil Shipley brings us the isEmpty function.


  • DLog only outputs NSLog in Debug.
  • ALog raises assertions in Debug and NSLogs in Release
  • ZAssert makes for simple assertions. Asserts in Debug, NSLogs in Release. This behaves very much like the STAssertTrue macro used in unit-testing bundles.

Don't even need to define DEBUG as Xcode 4 does that for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment