Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "HALContact.h"
- @interface HALContact ()
- // Redeclare readonly properties
- @property (readwrite) NSMutableArray *phoneNumbers;
- @property (readwrite) NSString *firstName;
- @end
- @implementation HALContact
- #pragma mark - Accessor Methods
- - (NSString *)firstName
- {
- if (!_firstName) {
- _firstName = [[NSString alloc]init];
- }
- _firstName = (__bridge_transfer NSString
- *)ABRecordCopyValue(_contactRef, kABPersonFirstNameProperty);
- return _firstName;
- }
- - (NSArray *)phoneNumbers {
- //Remove any phone numbers from previous contact.
- if (_phoneNumbers) {
- [_phoneNumbers removeAllObjects];
- }
- if (!_phoneNumbers) {
- //Create fresh _phoneNumbers array
- _phoneNumbers = [[NSMutableArray alloc]init];
- }
- ABMultiValueRef *phoneNumberRef = ABRecordCopyValue(_contactRef, kABPersonPhoneProperty);
- NSString *phoneNumber = [[NSString alloc] init];
- // Make sure multi value ref exists
- if (phoneNumberRef) {
- CFIndex numberOfPhoneNumbers = ABMultiValueGetCount(phoneNumberRef);
- for (CFIndex i = 0; i < numberOfPhoneNumbers; i++) {
- phoneNumber = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phoneNumberRef, i);
- CFStringRef label = ABMultiValueCopyLabelAtIndex(phoneNumberRef, i);
- if (label) {
- [_phoneNumbers addObject:phoneNumber];
- NSLog(@"phoneNumbers count in method: %d", _phoneNumbers.count);
- }
- CFRelease(label);
- }
- CFRelease(phoneNumberRef);
- }
- return _phoneNumbers;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement