How to get localizedstring for CNLabeledValue in swift3

余生长醉 提交于 2019-12-01 04:19:12

In Swift 3, CNLabeledValue is declared as:

public class CNLabeledValue<ValueType : NSCopying, NSSecureCoding> : NSObject, NSCopying, NSSecureCoding {
    //...
}

It's a generic type and if you use it in a proper context, you have no need to to cast its value. Swift 3 well infers the ValueType.

But in your code, Swift has no clue to infer the ValueType. It is sort of annoying, because ValueType is needless while executing the type method. But the type system of Swift needs it to be specified. If Swift cannot infer the type of the ValueType, you can explicitly give it.

Try this:

 let localizedLabel = CNLabeledValue<NSString>.localizedString(forLabel: phoneNumber.label!)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!