Skip to content

Instantly share code, notes, and snippets.

@AlanQuatermain
Created June 25, 2011 19:22
Show Gist options
  • Save AlanQuatermain/1046799 to your computer and use it in GitHub Desktop.
Save AlanQuatermain/1046799 to your computer and use it in GitHub Desktop.
A simple macro to create a non-retaining reference to an object for use within a block. For variable 'foo' will create non-retained variable '_block_foo' of type 'id'.
#if __has_feature(arr)
# if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
# define block_unretained(obj) id _block_##obj __weak = (obj)
# else
# define block_unretained(obj) id _block_##obj __unsafe_unretained = (obj)
#else
# define block_unretained(obj) id _block_##obj __block = (obj)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment