将地址簿联系人存储到 nsdictionary 中

发布于 2024-09-09 09:04:58 字数 670 浏览 7 评论 0原文

我仍在尝试使用 NSDictionaries,并且遇到了一种情况,我认为我需要使用它。本质上,我想将与每个联系人关联的所有电话号码存储到字典中。到目前为止,我有这个:

ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *thePeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); 
for (id person in thePeople)
{
    ABMultiValueRef phones =(NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty);
    NSString* name = (NSString *)ABRecordCopyCompositeName(person); 
    for (CFIndex i = 0; i < ABMultiValueGetCount(phones); i++)
    {
        NSString *phone = [(NSString *)ABMultiValueCopyValueAtIndex(phones,i) autorelease];
    }
}

我想知道如何使用 nsdictionary 来存储每个人,然后存储与该人关联的每个电话值的数组。

I'm still trying to wrap my head around using NSDictionaries, and have come into a situation where I believe I need to use one. essentially, I would like to store all the phone numbers associated with each contact into a dictionary. so far I have this:

ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *thePeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); 
for (id person in thePeople)
{
    ABMultiValueRef phones =(NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty);
    NSString* name = (NSString *)ABRecordCopyCompositeName(person); 
    for (CFIndex i = 0; i < ABMultiValueGetCount(phones); i++)
    {
        NSString *phone = [(NSString *)ABMultiValueCopyValueAtIndex(phones,i) autorelease];
    }
}

I was wondering how to use a nsdictionary to store each person, and then an array of each phone value that's associated with that person.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小苏打饼 2024-09-16 09:04:58

你想做什么?

您可以将所有姓名和电话号码放入 plist 中,如下所示:

ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *thePeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSMutableArray* allPeoplesDicts = [NSMutableArray array];
for (id person in thePeople)
{
    ABMultiValueRef phones =(NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty);
    NSString* name = (NSString *)ABRecordCopyCompositeName(person);
    NSMutableArray* phones = [[NSMutableArray alloc] init];
    for (CFIndex i = 0; i < ABMultiValueGetCount(phones); i++)
    {
        NSString *phone = [(NSString *)ABMultiValueCopyValueAtIndex(phones,i) autorelease];
        [phones addObject:phone];
    }
    NSDictionary* personDict = [[NSDictionary alloc] initWithObjectsAndKeys:name,@"Name",phones,@"PhoneNumbers",nil];
    [phones release];
    [allPeoplesDicts addObject:personDict];
    [personDict release];
}

What are you trying to do?

You can put all names and phonenumbers into a plist like this:

ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *thePeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSMutableArray* allPeoplesDicts = [NSMutableArray array];
for (id person in thePeople)
{
    ABMultiValueRef phones =(NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty);
    NSString* name = (NSString *)ABRecordCopyCompositeName(person);
    NSMutableArray* phones = [[NSMutableArray alloc] init];
    for (CFIndex i = 0; i < ABMultiValueGetCount(phones); i++)
    {
        NSString *phone = [(NSString *)ABMultiValueCopyValueAtIndex(phones,i) autorelease];
        [phones addObject:phone];
    }
    NSDictionary* personDict = [[NSDictionary alloc] initWithObjectsAndKeys:name,@"Name",phones,@"PhoneNumbers",nil];
    [phones release];
    [allPeoplesDicts addObject:personDict];
    [personDict release];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文