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