Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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]; 

You can use the stringByAppendingString like this:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top