I copied this method, line by line from the apple dev library and getting casting errors for the two NSString casts. How can those be resolved? (I am using ARC)
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
NSString* name = (NSString *)ABRecordCopyValue(person,
kABPersonFirstNameProperty);
self.firstName.text = name;
name = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
self.lastName.text = name;
[self dismissModalViewControllerAnimated:YES];
return NO;
}
Thank you for your help!
It sounds like you are using ARC.
ARC forbids standard casts between pointers to Objective-C objects and pointers of other types, including pointers to CoreFoundation objects.
The following code, which is correct under manual memory management, does not compile with ARC:
NSString* name = (NSString *)ABRecordCopyValue(person,
kABPersonFirstNameProperty);
To make it compile with ARC, you need to annotate the cast. See bridged casts.
NSString* name = (__bridge_transfer NSString *)ABRecordCopyValue(person,
kABPersonFirstNameProperty);
The __bridge_transfer annotation moves the value into ARC and transfers ownership, i.e., it tells ARC that this object is already retained, and that ARC doesn't need to retain it again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With