Cocoanetics / DTFoundation

Standard toolset classes and categories
BSD 2-Clause "Simplified" License
803 stars 237 forks source link

Replaces the unavailable 'objc_unretainedPointer' in Xcode 8 #107

Closed bibobode closed 8 years ago

bibobode commented 8 years ago

Replaces the unavailable 'objc_unretainedPointer' in Xcode 8 with a __bridge cast to resolve build error.

coveralls commented 8 years ago

Coverage Status

Coverage remained the same at 41.723% when pulling 42ccd52a188f33a420a50eaca4b90f64b29229c5 on bibobode:xcode8-build-error-fix into 4932fef6817720d3dfb8303c0b57eb9cef0421fb on Cocoanetics:develop.

ghost commented 8 years ago

It's not clear to me why the bridging was necessary in the first place, and why this doesn't suffice (it compiles):

id impBlockForIMP = block;

Would somebody please be able to explain?

huy-le commented 8 years ago

Are there any concerns to block this PR to merge into master?

bibobode commented 8 years ago

@lawrence-forooghian Your approach compiles. However, my concern is that your code may fail to compile on older Xcode versions. What do you think?

@huy-le I'm not sure what the process is for having it merged, but no one has expressed any concerns in the past few weeks.

odrobnik commented 8 years ago

@bibobode Is this approach backwards-compatible? If not, then we need conditional compilation so that earlier SDK versions can still build.

bibobode commented 8 years ago

@odrobnik Thank you for getting back so promptly :)

Yes, it is backwards compatible.

If you look at the Objective-C runtime header (http://opensource.apple.com/source/objc4/objc4-532/runtime/objc.h), you'll notice that it defines objc_unretainedPointer(o) as ((__bridge objc_objectptr_t)(id)(o)). Note that objc_objectptr_t is a typedef for void *. block is already defined as an id type so the remaining cast is unnecessary.