Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Adding contact list to NSMutableArray

obaidjawadobaidjawad Posts: 133Registered Users
Hi guys I'm working on storing the contact list in NSMutableArray and displaying it in NSLog at this point of time.

However I have used this code to do that

- (void)viewDidLoad {
// Implement viewDidLoad if you need to do additional setup after loading the view.
[super viewDidLoad];

ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book reference object
NSArray *abContactArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); // get address book contact array

NSInteger totalContacts =[abContactArray count];

for(NSUInteger loop= 0 ; loop < totalContacts; loop++)
{
ABRecordRef record = (ABRecordRef)[abContactArray objectAtIndex:loop]; // get address book record
// NSLog(@\"%@,%@,%@\",recordIdString,firstNameString,lastNameString);

[myarray addObject:firstNameString];
NSLog(@\"%@\",[myarray objectAtIndex:1]);

if(ABRecordGetRecordType(record) == kABPersonType) // this check execute if it is person group
{
ABRecordID recordId = ABRecordGetRecordID(record); // get record id from address book record

recordIdString = [NSString stringWithFormat:@\"%d\",recordId]; // get record id string from record id

firstNameString = (NSString*)ABRecordCopyValue(record,kABPersonFirstNameProperty); // fetch contact first name from address book
lastNameString = (NSString*)ABRecordCopyValue(record,kABPersonLastNameProperty); // fetch contact last name from address book
// NSLog(@\"%@,%@,%@\",recordIdString,firstNameString,lastNameString);

}
}

}



I have declared that myarray as a reference object for NSMutableArray in .h file.

However I'm unable to store the values in it. Can anybody help me out to fix it.
Post edited by obaidjawad on

Replies

  • reficulreficul Posts: 185Registered Users
    obaidjawad;430222 said:
    Hi guys I'm working on storing the contact list in NSMutableArray and displaying it in NSLog at this point of time.

    However I have used this code to do that

    - (void)viewDidLoad {
    // Implement viewDidLoad if you need to do additional setup after loading the view.
    [super viewDidLoad];

    ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book reference object
    NSArray *abContactArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); // get address book contact array

    NSInteger totalContacts =[abContactArray count];

    for(NSUInteger loop= 0 ; loop < totalContacts; loop++)
    {
    ABRecordRef record = (ABRecordRef)[abContactArray objectAtIndex:loop]; // get address book record
    // NSLog(@\"%@,%@,%@\",recordIdString,firstNameString,lastNameString);

    [myarray addObject:firstNameString];
    NSLog(@\"%@\",[myarray objectAtIndex:1]);

    if(ABRecordGetRecordType(record) == kABPersonType) // this check execute if it is person group
    {
    ABRecordID recordId = ABRecordGetRecordID(record); // get record id from address book record

    recordIdString = [NSString stringWithFormat:@\"%d\",recordId]; // get record id string from record id

    firstNameString = (NSString*)ABRecordCopyValue(record,kABPersonFirstNameProperty); // fetch contact first name from address book
    lastNameString = (NSString*)ABRecordCopyValue(record,kABPersonLastNameProperty); // fetch contact last name from address book
    // NSLog(@\"%@,%@,%@\",recordIdString,firstNameString,lastNameString);

    }
    }

    }



    I have declared that myarray as a reference object for NSMutableArray in .h file.

    However I'm unable to store the values in it. Can anybody help me out to fix it.
    Make sure to initialize your array before adding objects to it.
    Put these lines under your super viewDidLoad call:
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    self.myarray = arr;
    [arr release];
    If you really want something in this life you have to work for it. Now quiet, they're about to announce the lottery numbers.



    Homer J Simpson
Sign In or Register to comment.