我有这样的代码:
CNMutablePostalAddress *postalAddress = [[CNMutablePostalAddress alloc] init];
[postalAddress setCity:@"City"];
CNLabeledValue *city = [CNLabeledValue labeledValueWithLabel:CNPostalAddressCityKey value:postalAddress.city];
NSArray<CNLabeledValue<CNMutablePostalAddress *> *> *postalAddresses = @[city];
contact.postalAddresses = @[postalAddresses];我不知道如何进行这种转换,因为我需要在代码中将一个数组传递给contact.postalAddress。我试过一切可能的方法,但一无所获。
这段代码给了我一个例外:
*** Terminating app due to uncaught exception 'CNPropertyInvalidTypeException', reason: 'Labeled value (
"<CNLabeledValue: 0x12d5a14c0: identifier=080A5D1B-1F2D-4EE2-AB6F-BFAD523DA1C9, label=city, value=City>") has incorrect type __NSArrayI for key postalAddresses. It should be CNLabeledValue.'我怎么能这么做?
发布于 2016-05-20 07:16:07
这将创建一个新的邮政地址并将其添加到contact中。这就是你想要的,对吧?
CNMutablePostalAddress *postalAddress = [[CNMutablePostalAddress alloc] init];
postalAddress.city = @"City";
CNLabeledValue *labeledValue = [CNLabeledValue labeledValueWithLabel:CNLabelHome value:address];
contact.postalAddresses = @[labeledValue];发布于 2016-08-03 12:08:45
这是正确的实现。
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];https://stackoverflow.com/questions/37339538
复制相似问题