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?