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