aharren/LibComponentLogging-NSLog — Issue #2: Build Errors with ARC Enabled
Author: blakewatters
Created: 2011-10-16 05:00:29+00:00
State: open

When building a project importing LCLNSLog.h with Automatic Reference Counting enabled you encounter build warnings due to the use of NSAutoReleasePool in the macro. The patch below conditionally changes the implementation to be ARC compatible:

```objc

//
// Integration with LibComponentLogging Core.
//

#if __has_feature(objc_arc)
#define LCLNSLogAutoReleasePoolBegin() \
@autoreleasepool {
#else
#define LCLNSLogAutoReleasePoolBegin() \
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#endif

#if __has_feature(objc_arc)
#define LCLNSLogAutoReleasePoolEnd() \
}
#else
#define LCLNSLogAutoReleasePoolEnd() \
[pool release];
#endif

// Definition of _lcl_logger.
#define _lcl_logger(log_component, log_level, log_format, ...) { \
LCLNSLogAutoReleasePoolBegin(); \
NSLog(@"%s %s:%@:%d " log_format, \
_lcl_level_header_1[log_level], \
_lcl_component_header[log_component], \
[@__FILE__ lastPathComponent], \
__LINE__, \
## __VA_ARGS__); \
LCLNSLogAutoReleasePoolEnd(); \
}
```