Type conversion between iOS two frames-bridging technology

Source: Internet
Author: User

Don't say much, just give me an example. Scenario simulation: You need to develop an address book-related feature, access and add, and so on. At this point, the framework that needs to be used is the core Foundation. And this framework uses the C language, for example: Cfarrayref, Cfstringref and so on. Here is a simple code to read the contact information:

  

1- (void) Readmessage2 {3Abaddressbookref AbR =abaddressbookcreatewithoptions (null, NULL);4Cfarrayref Arrayr =abaddressbookcopyarrayofallpeople (AbR);5Cfindex count =Cfarraygetcount (Arrayr);6      for(Cfindex i =0; I < count; ++i) {7Abrecordref RECR =Cfarraygetvalueatindex (Arrayr, i);8Cfstringref STRR =Abrecordcopyvalue (RECR, kabpersonlastnameproperty);9NSLog (@"%@", STRR);Ten cfrelease (STRR); One     } A cfrelease (Arrayr); - cfrelease (AbR); -  the}

In the above code, do not know that you are not aware of, in order to prevent memory leaks, we must constantly use cfrelease to release resources, even under the arc. Plus the tangled function, these are very unaccustomed to ape apes accustomed to the foundation frame and arc. So how do you do it , using our Customary nsarray,nsstring (Foundation framework) no longer cares about memory? title, we only need to use bridging technology to solve:

  

1- (void) ReadMessage22 {3Abaddressbookref AbR =abaddressbookcreatewithoptions (null, NULL);4     5Nsarray *array = (__bridge Nsarray *) abaddressbookcopyarrayofallpeople (AbR);6     intCount =Array.count;7      for(inti =0; I < count; ++i) {8Abrecordref RECR =(__bridge abrecordref) array[i];9NSString *str = (__bridge NSString *) Abrecordcopyvalue (RECR, kabpersonlastnameproperty);TenNSLog (@"%@", str); One     } A      - cfrelease (AbR); -}

In contrast, is it possible to continue to happily write code?

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.