Last active
November 20, 2018 10:02
-
-
Save nicklockwood/1563325 to your computer and use it in GitHub Desktop.
ARC Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ARC Helper | |
// | |
// Version 2.2 | |
// | |
// Created by Nick Lockwood on 05/01/2012. | |
// Copyright 2012 Charcoal Design | |
// | |
// Distributed under the permissive zlib license | |
// Get the latest version from here: | |
// | |
// https://gist.github.com/1563325 | |
// | |
#import <Availability.h> | |
#undef ah_retain | |
#undef ah_dealloc | |
#undef ah_autorelease autorelease | |
#undef ah_dealloc dealloc | |
#if __has_feature(objc_arc) | |
#define ah_retain self | |
#define ah_release self | |
#define ah_autorelease self | |
#define ah_dealloc self | |
#else | |
#define ah_retain retain | |
#define ah_release release | |
#define ah_autorelease autorelease | |
#define ah_dealloc dealloc | |
#undef __bridge | |
#define __bridge | |
#undef __bridge_transfer | |
#define __bridge_transfer | |
#endif | |
// Weak reference support | |
#import <Availability.h> | |
#if !__has_feature(objc_arc_weak) | |
#undef ah_weak | |
#define ah_weak unsafe_unretained | |
#undef __ah_weak | |
#define __ah_weak __unsafe_unretained | |
#endif | |
// Weak delegate support | |
#import <Availability.h> | |
#undef ah_weak_delegate | |
#undef __ah_weak_delegate | |
#if __has_feature(objc_arc_weak) && \ | |
(!(defined __MAC_OS_X_VERSION_MIN_REQUIRED) || \ | |
__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_8) | |
#define ah_weak_delegate weak | |
#define __ah_weak_delegate __weak | |
#else | |
#define ah_weak_delegate unsafe_unretained | |
#define __ah_weak_delegate __unsafe_unretained | |
#endif | |
// ARC Helper ends |
@nverinaud you may prefer this older version if you are worried about performance:
https://gist.github.com/nicklockwood/1563325/4d32686a6058cb9bc409767ee7cc37a7993cb2df
Xcode gave me "Extra tokens at end of #undef directive" warning message.
#undef ah_autorelease autorelease
#undef ah_dealloc dealloc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@nverinaud you're right, but I changed it to use the ah prefix for everything some time ago (before your comment), so that criticism is no longer applicable.
The performance thing is basically a non-issue.