Skip to content

Instantly share code, notes, and snippets.

@wangmingfu
Forked from HIRANO-Satoshi/ARCMacro.h
Created November 19, 2012 18:27
Show Gist options
  • Save wangmingfu/4112538 to your computer and use it in GitHub Desktop.
Save wangmingfu/4112538 to your computer and use it in GitHub Desktop.
ARCMacro.h: Enables compilation both in ARC and non-ARC
/*
* ARCMacro.h 1.1 2012/05/29 https://gist.github.com/2823399
*
* ARCMacro.h realizes coexistence of both the ARC (Automatic
* Reference Counting) mode and the Non-ARC mode of Objective-C
* in the same source code. This macro works for iOS and Mac OS X.
*
* This is a by-product of joint research by AIST and The University of Ryukyu.
* HIRANO Satoshi (AIST), NAKAMURA Morikazu (U. Ryukyu) and GUAN Senlin (U. Ryukyu)
*
* Author: HIRANO Satoshi (AIST, Japan) on 2011/11/14
* Copyright 2011-2012 National Institute of Advanced Industrial Science
* and Technology (AIST), Japan. Apache License 2.0.
*
* Usage:
* #import "ARCMacro.h"
* [o1 RETAIN];
* o2 = [[o3 RETAIN] AUTORELEASE];
* [super DEALLOC];
*/
#if __has_feature(objc_arc)
#define RETAIN self
#define AUTORELEASE self
#define RELEASE self
#define DEALLOC self
#else
#define RETAIN retain
#define AUTORELEASE autorelease
#define RELEASE release
#define DEALLOC dealloc
#endif
@wangmingfu
Copy link
Author

ifndef MB_STRONG

if __has_feature(objc_arc)

#define MB_STRONG strong

else

#define MB_STRONG retain

endif

endif

ifndef MB_WEAK

if __has_feature(objc_arc_weak)

#define MB_WEAK weak

elif __has_feature(objc_arc)

#define MB_WEAK unsafe_unretained

else

#define MB_WEAK assign

endif

endif

if NS_BLOCKS_AVAILABLE

typedef void (^G7UIProgressHUDCompletionBlock)();

endif

if __has_feature(objc_arc)

#define MB_AUTORELEASE(exp) exp
#define MB_RELEASE(exp) exp
#define MB_RETAIN(exp) exp

else

#define MB_AUTORELEASE(exp) [exp autorelease]
#define MB_RELEASE(exp) [exp release]
#define MB_RETAIN(exp) [exp retain]

endif

if !__has_feature(objc_arc)

[xxx release];

if NS_BLOCKS_AVAILABLE

[xxxBlock release];

endif

[super dealloc];

endif

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