【发布时间】:2016-05-20 06:35:21
【问题描述】:
我有这个代码:
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.'
我该怎么做?
【问题讨论】:
-
你想做什么转换?保存和转换是不同的东西,请更正标题或故事。
-
我需要将“城市”保存在“contact.postalAddresses”中,但我需要先进行转换,否则应用程序将崩溃并出现异常。 @意义问题
标签: ios objective-c contacts cnpostaladdress