how can I Add a ABRecordRef to a NSMutableArray in iPhone?

前端 未结 4 1756
不思量自难忘°
不思量自难忘° 2021-01-02 05:26

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

   NSMutableArray* bContacts = [[NSMutableArray alloc] init         


        
4条回答
  •  隐瞒了意图╮
    2021-01-02 05:58

    Create an NSObject wich store your ABRecordRef like this :

    // ABContact.h
    @interface ABContact : NSObject
    {
        ABRecordRef _record;
    }
    
    @property (nonatomic, readonly) NSDate *birthday;
    
    - (id)initWithRecord:(ABRecordRef)aRecord;
    
    @end
    
    // ABContact.m
    @implementation ABContact
    
    #pragma mark - Init
    
    - (id)initWithRecord:(ABRecordRef)aRecord;
    {
        if ((self = [super init]))
            _record = CFRetain(aRecord);
        return self;
    }
    
    
    #pragma mark - Getter
    
    - (NSDate *)birthday
    {
        return (NSDate *)ABRecordCopyValue(record, kABPersonBirthdayProperty) autorelease];
    }
    
    
    #pragma mark - Memory management
    
    - (void)dealloc
    {
        CFRelease(_record);
        [super dealloc];
    }
    
    @end
    


    You should take a look at the Erica Sadum library the author of the iPhone cookbook. Here is the code wich inspire this code -> url

提交回复
热议问题