Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get localizedstring for CNLabeledValue in swift3

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?

like image 908
Aldo Lazuardi Avatar asked Jul 11 '16 05:07

Aldo Lazuardi


1 Answers

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!)
like image 177
OOPer Avatar answered Nov 17 '22 14:11

OOPer