In Swift 3, CNLabeledValue
is declared as:
public class CNLabeledValue<ValueType : NSCopying, NSSecureCoding> : NSObject, NSCopying, NSSecureCoding {
//...
}
You need to make Swift able to infer the ValueType
, which conforms to NSCopying
and NSSecureCoding
.
Unfortunately, String
or String?
does not conform to neither of them.
And, Swift 3 removed some implicit type conversions, such as String
to NSString
, you need to cast it explicitly.
Please try this:
let workEmail = CNLabeledValue(label:"Work Email", value:(emp.getEmail() ?? "") as NSString)
contact.emailAddresses = [workEmail]
Or this:
if let email = emp.getEmail() {
let workEmail = CNLabeledValue(label:"Work Email", value:email as NSString)
contact.emailAddresses = [workEmail]
}
(Maybe the latter is the better, you should not make an empty entry.)
And one more, as suggested by Cesare, you'd better use predefined constants like CNLabel...
for labels as far as possible:
if let email = emp.getEmail() {
let workEmail = CNLabeledValue(label: CNLabelWork, value: email as NSString)
contact.emailAddresses = [workEmail]
}