如何在swift3中获得CNLabeledValue的本地化string
在迅速2我使用CNLabeledValue.localizedStringForLabel(phoneNumber.label)
并正常工作。
在swift 3我试过这行CNLabeledValue.localizedString(forLabel: phoneNumber.label!)
但得到generic parameter 'ValueType' could not be inferred
错误
如何在swift3中获取CNLabeledValue的本地化string?
在Swift 3中, CNLabeledValue
被声明为:
public class CNLabeledValue<ValueType : NSCopying, NSSecureCoding> : NSObject, NSCopying, NSSecureCoding { //... }
这是一个genericstypes,如果你在适当的环境中使用它,你不需要投入它的value
。 Swift 3很好地推断了ValueType
。
但是在你的代码中,Swift没有任何线索来推断ValueType
。 这有点烦人,因为在执行types方法时ValueType
是不必要的。 但是Swift的types系统需要指定它。 如果Swift不能推断出ValueType
的types,你可以明确地给它。
尝试这个:
let localizedLabel = CNLabeledValue<NSString>.localizedString(forLabel: phoneNumber.label!)
- 如何将UILongPressGestureRecognizer添加到UITextField?
- Xcode升级到4.5后应用程序崩溃。 将保留的对象分配给unsafe_unretainedvariables