https://developer.apple.com/library/ios/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/ Tollfreebridgedtypes.html
Toll-Free bridge is essentially the conversion of the types in the core Foundation framework and the Cocoa Foundation framework, and in some functions that contain toll-free type parameters, you can use the core The type of foundation can also be used with the type of Cocoa Foundation
Ps:
Core Foundation framework: A set of C language interfaces, such as some classes at the beginning of CF, such as Cfstring
COCOA Foundation framework: OBJECITVE-C interfaces, such as those at the beginning of the NS, such as NSString
Example ( non-arc):
NSString *string = @ "Test string";
Cfstringref cfstring = (cfstringref) string;
The above code in the case of non-arc application, if in the case of arc need to use some keywords (_bridge, _bridge_retained, _bridge_transfer) conversion, or the compiler will error
_bridge: Only type conversions, object ownership unchanged
_bridge_retained: Cocoa Foundation object is converted to CF object, the memory of the CF object needs to be released by itself (Cfrelease)
_bridge_transfer: CF objects are converted to Cocoa Foundation objects, COCOA Foundation's object memory is managed by arc
Note: CF objects are not managed by arc
Example (ARC):
_bridge:
NSString *string = @ "Test string";
Cfstringref cfstring = (_bridge cfstringref) string;
...
Cfrelease (cfstring);
If the string object is freed, then Cfstring will be released.
_bridge_retained:
NSString *string = @ "Test string";
Cfstringref cfstring = (_bridge_retained cfstringref) string;
...
Cfrelease (cfstring);
If the string object is freed, cfstring will not be freed because _bridge_retained will add a reference to the
_bridge_transfer:
Cfstringref cfstring = cfstringcreate ... () ...;//or Cfstringref cfstring = Cfstr ("Hello, World."); Cfstr created string cannot be modified, not released through cfstring until end of program is released
NSString *string = (_bridge_transfer nsstring*) cfstring;
At this point the string is managed by the arc, and even if Cfstring is freed, the string will still exist
IOS Toll-Free Bridge