Objective-c Objects and core Foundation objects

Source: Internet
Author: User

Core Foundation objects are primarily used in the core Foundation framework written in C and reference the counted objects. There are very few differences with OBJECTIVE-C objects. No matter which framework generates the object, once generated, Can be used in both frameworks. This conversion does not require additional CPU resources and is also known as a "Free bridge".


/**************************** (1) ***********************/

/*

Cftyperef Cfbridgingretain (id X) {

Return (__bridge_retained cftyperef) X;

}

ID cfbridgingrelease (cftyperef X) {

return (__bridge_transfer ID) X;

}

*/

cfmutablearrayref cfobject = NULL;

{

ID obj = [[nsmutablearrayalloc] init];

Cfobject =cfbridgingretain(obj);

// You can also use Cfobject = (__bridge_retained cfmutablearrayref) obj;

/*

Does the ARC mechanism work in the Core Foundation framework ?

The output is printed as follows :

Retain count = 2

Retain count = 1

So the ARC mechanism does not work under the Core Foundation

*/

Cfshow (Cfobject);

printf ("Retain count =%ld\n",cfgetretaincount(cfobject));

}

printf("Retain count =%ld\n",cfgetretaincount(cfobject));

Cfrelease (Cfobject);

/**************************** (2) ***********************/

// use __bridge conversion to replace Cfbridgingretain or __bridge_retained conversion

/*

Cfobject = (__bridge cfmutablearrayref) obj;

However, the use of __bridge does not alter the holding of objects .

*/


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Objective-c Objects and core Foundation objects

Related Article

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.