Understanding of __bridge, __bridge_retained and __bridge_transfer in IOS

The problem of CFObject and NSObject conversion, because ARC cannot manage the life cycle of Core Foundation Object, between Core Foundation and ARC, we need to use the three conversion keywords __bridge, __bridge_retained and __bridge_transfer. 

 

Apple's official document (https://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html):


__bridge only performs type conversion, but does not modify the object (memory) management rights; 

__bridge_retained (CFBridgingRetain can also be used) converts Objective-C objects to Core Foundation objects, and at the same time gives us the management rights of the objects (memory), follow-up Need to use CFRelease or related methods to release the object; 
 

__bridge_transfer (CFBridgingRelease can also be used) converts Core Foundation objects into Objective-C objects, and at the same time transfers the management of the objects (memory) to ARC.

Guess you like

Origin blog.csdn.net/qq_28285625/article/details/113939839