我想在数组中或在保存之前合并两个对象
我正在从 ABpeoplepickerNavcontroller 保存名字和姓氏,我想在保存到数组之前合并名字和姓氏,以便当我检索它时,它们会在一起。第一个代码是正在创建的对象:
// setting the first name
firstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
// setting the last name
lastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
这是我保存它的位置:
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:firstName.text];
[array addObject:lastName.text];
[array addObject:addressLabel.text];
[array writeToFile:recipient atomically:NO];
[array release];
我可以在一行上保存添加两个对象吗?或者我可以在添加到数组之前合并对象吗?
谢谢,郑重声明……这个网站和帮助我的人都很棒。
迈克尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定你所说的合并是什么意思。如果要将一个字符串附加到另一个字符串,请执行以下操作:
I am not sure what you mean by merging. If you want to append one string to the other do the following:
您可以像这样使用
stringByAppendingString
:[array addObject:[firstName.text stringByAppendingString:lastName.text]]
;You can use the
stringByAppendingString
like this:[array addObject:[firstName.text stringByAppendingString:lastName.text]]
;来自 iPhone 通讯录编程指南:
“然而,在实际应用中,推荐使用 ABRecordCopyCompositeName 函数来显示一个人的全名。它将名字和姓氏按照用户喜欢的顺序排列,这提供了更统一的用户体验。”
这里的解决方案可以工作,但如果您只使用复合名称,您可能根本不需要这样做。
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.