Skip to content

Instantly share code, notes, and snippets.

@gschandler
Last active December 19, 2015 06:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gschandler/5912002 to your computer and use it in GitHub Desktop.
Retain/Release/Autorelease macros for using non-ARC code with an ARC project.
#ifdef __OBJC__
#ifndef WBRetain
#if __has_feature(objc_arc)
# define WBRetain(obj) obj
#else
# define WBRetain(obj) [obj retain]
#endif
#endif
#ifndef WBRelease
#if __has_feature(objc_arc)
# define WBRelease(obj)
#else
# define WBRelease(obj) [obj release], obj = nil
#endif
#endif
#ifndef WBAutorelease
#if __has_feature(objc_arc)
# define WBAutorelease(obj) obj
#else
# define WBAutorelease(obj) [obj autorelease]
#endif
#endif
#ifndef WBSuperDealloc
// replace '[super dealloc];' in 'dealloc' body with this macro
// ie
// - (void)dealloc
// {
// WBRelease(ivar1);
// WBRelease(ivar2);
// WBSuperDealloc;
// }
//
#if __has_feature(objc_arc)
# define WBSuperDealloc [super dealloc]
#else
# define WBSuperDealloc
#endif
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment