In swift 2 I'm using CNLabeledValue.localizedStringForLabel(phoneNumber.label)
and works fine.
In swift 3 I tried this line CNLabeledValue.localizedString(forLabel: phoneNumber.label!)
but got generic parameter 'ValueType' could not be inferred
error
How to get localizedstring for CNLabeledValue in swift3?
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!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With