数组中的键值如array [0]等

时间:2013-01-12 13:22:25

标签: iphone

我正在使用此代码

NSDictionary *yourDictionary;

NSArray * yourKeys;
yourKeys = [yourDictionary allValues];

获取字典的值。但我希望这种形式的数组输出:array [0],array [1],而我在控制台中得到输出如下: -

2013-01-12 18:44:10.213 Birthday_Reminder[2871:c07] (
{
},
"Arpit Sihare")

等值。 所以plz帮助我以这种形式获取这些值,并且我正在使用KABPersonfirstname属性从地址簿中检索这些名称。

  ABAddressBookRef addressBook = ABAddressBookCreate();
    NSArray *thePeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
    NSMutableArray* allPeoplesDicts = [NSMutableArray array];
    for (id person in thePeople)
    {
        ABMultiValueRef phone =(NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty);
        NSString* name = (NSString *)ABRecordCopyCompositeName(person);
       // NSMutableArray* phones = [[NSMutableArray alloc] init];
        NSDictionary *phones=[[NSDictionary 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];


        NSArray * yourKeys;
        yourKeys = [personDict allValues];


        NSLog(@"%@",yourKeys);
        [allPeoplesDicts addObject:personDict];
        [personDict release];
    }

我希望以数组形式使用firstname,当我使用nslog(@“%@”,array [0])时,它应该首先打印存储在数组中的值,并很快就像数组[1] ....

1 个答案:

答案 0 :(得分:0)

要理解你想说的话太难了。我试过了......

如果您只想存储所有firstName(我认为这是您的密钥),那么只需将yourKeys设为NSMutableArray,然后将names添加到该数组即可。 :

[yourKeys addObject:names];

简单!!