在iPhone中的NSMutableArray中添加ABReco

在iPhone中的NSMutableArray中添加ABReco

本文介绍了如何在iPhone中的NSMutableArray中添加ABRecordRef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个ABRecordRef(s)数组来存储具有有效生日字段的联系人。

I want to create an array of ABRecordRef(s) to store contacts which have a valid birthday field.

   NSMutableArray* bContacts = [[NSMutableArray alloc] init];
   ABAddressBookRef addressBook = ABAddressBookCreate();
   CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
   CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);

   for( int i = 0 ; i < nPeople ; i++ )
   {
       ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i );
       NSDate* birthdayDate = (NSDate*) ABRecordCopyValue(ref, kABPersonBirthdayProperty);
       if (birthdayDate != nil){
           [bContacts addObject:ref];
       }
   }

编译器显示此警告:
警告:传递'addObject:'的参数1'从指针目标类型中丢弃限定符
我在网上搜索并发现我必须将ABRecordRef转换为ABRecord *以便能够存储在NSMutableArray中。

The compiler shows this warning:warning: passing argument 1 of 'addObject:' discards qualifiers from pointer target typeI searched the web and found I have to cast ABRecordRef to a ABRecord* to be able to store in a NSMutableArray.

[bContacts addObject:(ABRecord*) ref];

但似乎ABRecord不是iOS框架的一部分。现在我如何将ABRecordRef存储到NSMutableArray?

But it seems ABRecord is not part of iOS frameworks. Now how I store ABRecordRef to NSMutableArray?

推荐答案

[bContacts addObject:(id) ref];

这篇关于如何在iPhone中的NSMutableArray中添加ABRecordRef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:03