Skip to content

Instantly share code, notes, and snippets.

@Abizern
Forked from danielctull/dct_weak.h
Created November 10, 2011 04:19
Show Gist options
  • Save Abizern/1354106 to your computer and use it in GitHub Desktop.
Save Abizern/1354106 to your computer and use it in GitHub Desktop.
ARC macros for weak references
#import <Availability.h>
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_4_3
#warning "This library uses ARC which is only available in iOS SDK 4.3 and later."
#endif
#if !defined dct_weak && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
#define dct_weak weak
#define __dct_weak __weak
#define dct_nil(x)
#elif !defined dct_weak && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_3
#define dct_weak unsafe_unretained
#define __dct_weak __unsafe_unretained
#define dct_nil(x) x = nil
#endif
@steipete
Copy link

"ARC is supported in Xcode 4.2 for Mac OS X v10.6 and v10.7 (64-bit applications) and for iOS 4 and iOS 5. Weak references are not supported in Mac OS X v10.6 and iOS 4." (http://developer.apple.com/library/mac/#releasenotes/ObjectiveC/RN-TransitioningToARC/_index.html#//apple_ref/doc/uid/TP40011226)

So stating that you need 4.3 is not true. Anway, the macro idea is great, thanks!

@danielctull
Copy link

I've also just realised that there should be a check for Mac OS version as well. Will have a look at some point :)

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