[swift-users] CNLabeledValue var

German Laullon laullon at gmail.com
Wed Jan 11 04:05:48 CST 2017


var toExcludeOrCopy : AnyObject?

Could help me on some cases...

But if I try this:

var props = [AnyObject]()
props += contact.phoneNumbers

( "contact" is as CNContact, so "contact.phoneNumbers" is

I get this error:
/Users/laullon/xcode/bipo/BiPo/MergePreview.swift:82:21: Cannot convert
value of type '[AnyObject]' to expected argument type 'inout _'

props.append(contentsOf: contact.phoneNumbers)

I get this error:
/Users/laullon/xcode/bipo/BiPo/MergePreview.swift:83:33: Extraneous
argument label 'contentsOf:' in call

Any Idea?

Germán Laullón

On Tue, Jan 10, 2017 at 12:36 AM, Hooman Mehr <hooman at mac.com> wrote:

> Ouch!
> 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/20170111/bfb9cac7/attachment.html>

More information about the swift-users mailing list