这是我用来从通讯录中获取联系人姓名和电子邮件的功能。
-(void) fetchFriendsAllDetails {
NSMutableArray *allEmails = [[NSMutableArray alloc] initWithCapacity:_peopleList.count];
for (int i = 0; i < _peopleList.count; i++) {
ABRecordRef person = (__bridge ABRecordRef)([_peopleList objectAtIndex:i]);
ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
NSString *name=[[NSString stringWithFormat:@"%@",(__bridge_transfer NSString *)ABRecordCopyCompositeName(person)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSLog(@"id:%d,name:%@",i,name);
for (int j=0; j < ABMultiValueGetCount(emails); j++) {
NSString* email = (__bridge NSString*)ABMultiValueCopyValueAtIndex(emails, j);
[allEmails addObject:email];
NSLog(@"id:%d,email:%@",i,email);
}
}
}
上面的输出如下:
id:0,name:John Appleseed
id:0,email:John-Appleseed@mac.com
id:1,name:Kate Bell
id:1,email:kate-bell@mac.com
id:1,email:www.icloud.com
id:2,name:Anna Haro
id:2,email:anna-haro@mac.com
id:3,name:Daniel Higgins Jr.
id:3,email:d-higgins@mac.com
id:4,name:David Taylor
id:5,name:Hank M. Zakroff
id:5,email:hank-zakroff@mac.com
我想在上面的函数中创建一个字典,它将包含以下格式的输出
{
id:0
name:John Appleseed
email:John-Appleseed@mac.com
selectedFlag:NO
},
{
id:1
name:Kate Bell
email:kate-bell@mac.com, www.icloud.com
selectedFlag:NO
},
{
id:2
name:Anna Haro
email:John-Appleseed@mac.com
selectedFlag:NO
},
{
id:3
name:Daniel Higgins Jr.
email:d-higgins@mac.com
selectedFlag:NO
},
{
id:4
name:David Taylor
email:""
selectedFlag:NO
},
id:5
nameHank M. Zakroff
email:hank-zakroff@mac.com
selectedFlag:NO
}
我对 NSMutableDictionary 有基本的了解,但不详细了解如何实现这一点。你能帮我创建它吗?