I start learning programming with Objective-C, and do not have much knowledge of C. So, bridge casting in iOS 6 is still somewhat confusing for me.
Here is the scenario:
I have a person ABRecordID stored in CoreData as 'NSNumber' attribute. Later on, I would like to access to that person directly, so I want to use the person's ABRecordID to access the contact info using ABAddressBook. Noticed that ABAddressBookGetPersonWithRecordID needs ABRecordID, below is how I perform casting in my code...
address_book = ABAddressBookCreate();
ABRecordID rec_id = (__bridge ABRecordID)person.record_id;
However, This was not successful and I was given incompatible types casting 'int' into 'ABRecordID' (aka 'int') with a __bridge cast.
Already confused as it is, what would be a proper way to bridge cast between ARC type and CF type?
Also, in which case should I use (__bridge retained) instead of (__bridge)?
The
ABRecordIDis a synonym (typedef) forint32_twhich is a 32-bit integer. So typecasting is not the proper approach. You want to create anNSNumberwith the value of the id.and later:
Please note that bridging and ARC are irrelevant when going to/from ABRecordId and NSNumber. There is no use of any of the
CFtypes in this case. You'll know when you are usingCFtypes because you'll have a variable whose type begins withCF(such asCFArrayRef).