문제

I'm reading the docs on how to work with the iOS AddressBook. While so far I understand the general mechanics of it I'm having trouble understanding the rationale behind how this framework in particular is built. I've only just finished my second app so while I have seen a couple of the iOS frameworks I'm not that experienced. How this framework differs from what I've seen so far completely puzzles me.

I'm sure Apple's engineers had their reasons for going about this the way they did but I'm asking because I think it's very valuable to understand, or at least try to understand, the thought process behind it.

This is the documented way to get a string value from an AddressBook record:

NSString* name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);

This is the documented way to get a contact's value, in this case the phone numbers, if any:

ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);

And finally you count the phone numbers like this:

ABMultiValueGetCount(phoneNumbers)

My question is...

What's the rationale behind all these little functions like ABRecordCopyValue(), ABMultiValueGetCount(), etc, when working with other frameworks is completely different. I mean, why working with the AddressBook doesn't look like this?

NSAddressBookContact *person = [[NSAddressBookContact alloc] initWithRecordReference:myRecord];
NSString *name = person.name;
NSLog(@"Phone number count: %i", [person.phoneNumbers count]);
도움이 되었습니까?

해결책

Some frameworks have an Objective-C API; others have a C API. For example, Core Foundation is all C, while Cocoa and Cocoa Touch are Objective-C.

None of us knows for certain why Apple chose to write a C API instead of an Objective-C API for AddressBook specifically, but one might guess that they had a need to access data in the address book from lower levels. For example, the software component that handles incoming phone calls is probably pretty low-level (at least compared to third party apps) and might require a C API.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top