The Core Foundation to introduce

Sometimes you might need to use Core Foundation objects (such as CFArrayRef or CFMutableDictionaryRef) for which the compiler does not automatically manage their lifecycle, You need to manage their ownership using methods such as CFRetain or CFRelease.

If you want to do conversion between Core Foundation objects and Objective-C objects, you can use toll-free Bridging.

Since THE methods such as retain and release cannot be directly used by ARC, it is necessary to inform OC of the holding situation of CF pointer during conversion. Similarly, OC should also inform its holding situation when converting to CF pointer.

Three conversion methods

Toll-free Bridging can be converted using a modifier

(1)__bridge

Used for direct conversion between two Pointers, regardless of holding;

(2)__bridge_retained

This is used to convert the OC pointer to the CF pointer, after which the CF pointer also holds the object. That is, the converted pointer that is assigned also holds the object. Using the CFBridgingRetain function has the same effect;

(3)__bridge_transfer

Used to convert a CF pointer (” non-OC pointer “) to an OC pointer, after which the CF pointer no longer holds an object. That is, the converted assignment pointer no longer holds the object. Using CFBridgingRelease has the same effect.