[swift-users] CNLabeledValue var

Hooman Mehr hooman at mac.com
Mon Jan 9 17:36:43 CST 2017


This is a side effect of ObjC lightweight generics being imported as Swift generics in Swift 3.0.

Since there is no common superclass that satisfies NSCopying & NSSecureCoding and the fact that NSSecureCoding has static requirements means you can’t do it (at least without hacks such as extending NSObject to conform to both protocols or creating a wrapper class and creating a non-generic subclass of CNLabeledValue and using it instead).

For now, you have to use  

var toExcludeOrCopy : AnyObject?

This is worthy of a bug report and points to a serious issue: The “limitations” that result from importing ObjC lightweight generics as Swift generics. One possible solution can be implementation of “Enhanced Existentials <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170102/029919.html>”.

> On Jan 9, 2017, at 11:23 AM, German Laullon via swift-users <swift-users at swift.org> wrote:
> Hi All
> I just upgrade to Swift 3. After open and convert my codes I found lots of errors. One of them is about CNLabeledValue.
> With Swift 2.3, it works well with:
> var toExcludeOrCopy : CNLabeledValue?  
> With Swift 3, it gives me the error message:
> Reference to generic type 'CNLabeledValue' requires arguments in <...>.
> After I fixed it with XCode, it changed to:
>  var toExcludeOrCopy : CNLabeledValue<AnyObject>?  
> However, Xcode gives me error message with this fix:
> Type 'AnyObject' does not conform to protocol 'NSCopying'.
> I know the error is because of the generic type but I don't know how to declare with CNLabeledValue. My purpose is to store any the CNLabeledValue including phone number, email, address etc to one var.
> Any help will be appreciate.
> Germán Laullón
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170109/2de1516c/attachment.html>

More information about the swift-users mailing list