Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在Objective-C中保存服装_Ios_Objective C_Contacts_Cnpostaladdress - Fatal编程技术网

Ios 在Objective-C中保存服装

Ios 在Objective-C中保存服装,ios,objective-c,contacts,cnpostaladdress,Ios,Objective C,Contacts,Cnpostaladdress,我有以下代码: CNMutablePostalAddress *postalAddress = [[CNMutablePostalAddress alloc] init]; [postalAddress setCity:@"City"]; CNLabeledValue *city = [CNLabeledValue labeledValueWithLabel:CNPostalAddressCityKey value:postalAddress.city]; NSArray<CNLabe

我有以下代码:

CNMutablePostalAddress *postalAddress = [[CNMutablePostalAddress alloc] init];
[postalAddress setCity:@"City"];

CNLabeledValue *city = [CNLabeledValue labeledValueWithLabel:CNPostalAddressCityKey value:postalAddress.city];

NSArray<CNLabeledValue<CNMutablePostalAddress *> *> *postalAddresses = @[city];

contact.postalAddresses = @[postalAddresses];

我该怎么做?

这将创建一个新的邮政地址,并将其添加到
联系人中。这就是你想要的,对吗

CNMutablePostalAddress *postalAddress = [[CNMutablePostalAddress alloc] init];
postalAddress.city = @"City";

CNLabeledValue *labeledValue = [CNLabeledValue labeledValueWithLabel:CNLabelHome value:address];
contact.postalAddresses = @[labeledValue];

这是正确的实现

CNMutablePostalAddress *postalAddress = [[CNMutablePostalAddress alloc] init];
postalAddress.street = @"1 Market Street";
postalAddress.city = @"Sydney";
postalAddress.postalCode = @"2000";
postalAddress.state = @"NSW";
CNLabeledValue *address = [CNLabeledValue labeledValueWithLabel:CNLabelWork value:postalAddress];
contact.postalAddresses = @[address];

你想做什么转换?保存和转换是不同的事情,请更正标题或故事。我需要在“contact.postalAddresss”中保存“city”,但我需要在之前进行转换,否则应用程序将崩溃@意义重大!非常感谢!:)@意义-matters@David很乐意帮忙!如果你不知道的话,你也可以投票赞成这个答案;-)
CNMutablePostalAddress *postalAddress = [[CNMutablePostalAddress alloc] init];
postalAddress.street = @"1 Market Street";
postalAddress.city = @"Sydney";
postalAddress.postalCode = @"2000";
postalAddress.state = @"NSW";
CNLabeledValue *address = [CNLabeledValue labeledValueWithLabel:CNLabelWork value:postalAddress];
contact.postalAddresses = @[address];