Data conversion between Cocoafoundation and corefoundation (bridging __bridge)

Source: Internet
Author: User

Arc only manages objective-c pointers (retain, release, autorelease), does not manage corefoundation pointers, cf pointers are managed manually by manual cfretain and cfrelease, note, There is no autorelease in cf.

The cocoafoundation pointer and the corefoundation pointer conversion, need to consider is the ownership of the object of the point. ARC provides 3 modifiers to manage.

1. __bridge, do nothing, just convert. In this case:

i). Conversion from cocoa to core requires manual cfretain, otherwise the pointer passed out when the cocoa pointer is released is invalid.

II). Conversion from core to cocoa requires manual cfrelease, otherwise the object reference count is still 1 after the cocoa pointer is released and will not be destroyed.

2. __bridge_retained, automatically call Cfretain after conversion, that is, to help automatically solve the above I situation.

(__bridge_retained or Cfbridgingretain,arc transfers the ownership of the object, which needs to be corefoundation processed.) )

3. __bridge_transfer, automatically call cfrelease after conversion, that is, to help automatically solve the situation of the above II.

(__bridge_transfer or cfbridgingrelease,corefoundation gives the object ownership to arc, which is handled automatically by arc.) )

Data conversion between Cocoafoundation and corefoundation (bridging __bridge)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.