In Swift 3, CNLabeledValue declared as:
public class CNLabeledValue<ValueType : NSCopying, NSSecureCoding> : NSObject, NSCopying, NSSecureCoding {
You need to force Swift to draw a ValueType output that matches NSCopying and NSSecureCoding .
Sorry, String or String? does not match any of them.
And, Swift 3 removed some implicit type conversions, such as String to NSString , you need to explicitly specify it.
Please try the following:
let workEmail = CNLabeledValue(label:"Work Email", value:(emp.getEmail() ?? "") as NSString) contact.emailAddresses = [workEmail]
Or that:
if let email = emp.getEmail() { let workEmail = CNLabeledValue(label:"Work Email", value:email as NSString) contact.emailAddresses = [workEmail] }
(Maybe the latter is better; you should not make an empty entry.)
And one more, as Cesare suggested, you better use predefined constants like CNLabel... for shortcuts as much as possible:
if let email = emp.getEmail() { let workEmail = CNLabeledValue(label: CNLabelWork, value: email as NSString) contact.emailAddresses = [workEmail] }
Ooper
source share