Many times the corefoundation function is used, and its return value is the object of the corefoundation frame, which can be done using bridging if the object you want to convert to the foundation frame.
Example code:
CFSTRINGREF FirstName = abrecordcopyvalue (person, kabpersonfirstnameproperty); = Abrecordcopyvalue (person, kabpersonlastnameproperty); *firstname = (__bridge NSString *) (firstName); *lastname = (__bridge NSString *) (lastName);
However, there is a possibility of a memory leak using this bridging method.
Functions that use Corefoundation in Arc mode need to take into account the memory leak problem, the above bridge method is simply to give the Corefoundation framework's object ownership to the foundation framework to use, and cannot manage the object's memory, If we want to manage this object's memory, we can use a different kind of bridging method.
Example code:
NSString *firstname = (__bridge_transfer NSString *) (firstName); *lastname = (__bridge_transfer NSString *) (lastName);
Summarize:
- __bridge Type: The object ownership of the Corefoundation framework is given to the foundation framework for use, but the objects in the foundation framework cannot manage the memory of the object.
- __bridge_transfer objective-c Type: The object ownership of the Corefoundation framework is assigned to the foundation to manage, if the object in the foundation is destroyed, then our previous object ( Corefoundation) will be destroyed together.
Using the __bridge_transfer objective-c type Bridge, you will no longer have to manually manage the memory yourself!
ios-Bridge Connection method