Posted By

daknok on 06/11/11


Tagged

prefix-header


Versions (?)

Prefix header with better releasing, freeing and logging


 / Published in: Objective C
 

This prefix header adds SXRelease(), SXFree() and SXLog() which can be used instead of -[<NSObject> release], free() and NSLog(). In order to use SXLog(), you must have DEBUG defined somewhere, such as in the build settings of the debug configuration.

Please note that the while(0){} is to prevent errors where a single ; is not permitted. The optimizer will remove this from the assembly code.

  1. #ifdef __OBJC__
  2.  
  3. #import <CoreFoundation/CoreFoundation.h>
  4. #import <Foundation/Foundation.h>
  5. #import <AppKit/AppKit.h>
  6. #import <Cocoa/Cocoa.h>
  7.  
  8. #define SXRelease(o) [o release]; o = nil
  9.  
  10. #ifdef DEBUG
  11. #define SXLog(...) NSLog(@"%@ > %s (line %d): %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:__VA_ARGS__, nil])
  12. #else
  13. #define SXLog(...) while(0){}
  14. #endif
  15.  
  16. #endif
  17.  
  18. #define SXFree(p) free(p); p = NULL

Report this snippet  

You need to login to post a comment.