views:

77

answers:

3

I am saving the first and last name from ABpeoplepickerNavcontroller, I would like to merge the first and last name prior to saving into an array so that when i retrieve it, they would be together. The first code is the object being created:

// setting the first name
firstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);

// setting the last name
lastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);   

Here's where I save it:

NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:firstName.text];
[array addObject:lastName.text];
[array addObject:addressLabel.text];

[array writeToFile:recipient atomically:NO];
[array release];

Can I save add two objects on one line? or Can I merge the objects prior to adding to array?

Thanks, and for the record...this site and the people who have helped me have been fantastic.

Michael

+2  A: 

I am not sure what you mean by merging. If you want to append one string to the other do the following:

NSString *joinedNamed = [NSString stringWithFormat:@"%@ %@", firstName.text, lastName.text]; 
Felix
Thanks also , I used the CompositeName
Michael Robinson
+1  A: 

You can use the stringByAppendingString like this:

[array addObject:[firstName.text stringByAppendingString:lastName.text]];

Mihir Mathuria
Thanks, the Compositename was a better fit.
Michael Robinson
A: 

From the Address Book Programming Guide for iPhone:

"However, in actual applications, the function ABRecordCopyCompositeName is the recommended way to get a person’s full name to display. It puts the first and last name in the order preferred by the user, which provides a more uniform user experience."

The solutions here will work but it's something you may not need to do at all if you just use the composite name.

Adam Eberbach
Thanks for all the responses, This was the best choice...I forgot about that compositename function. 5 weeks ago sounds is an eternity when remembering code. Thanks everyone.
Michael Robinson