[swift-users] Strange compilation error when calling required initializer on generic type parameter

Christos Chryssochoidis c.chryssochoidis at gmail.com
Sun Sep 18 11:19:37 CDT 2016


Hi everyone,

I'm using the new Xcode 8/Swift 3 and I'm trying to figure out why the
first function in the snippet below compiles correctly, while the other one
does not.

import Foundation

import CoreData


protocol P {

    init?(i: Int)

}



class C {

    func f<T: NSObject>(i: Int) -> T? where T: P {

        return T(i: i)  // compiles OK

    }



    func g<T: NSManagedObject>(i: Int) -> T? where T: P {

        return T(i: i)  // doesn't compile: "Incorrect argument label in
call

                 ^      // (have: 'i:', expected 'context:')

    }

}


Is this some bug of the Swift compiler or am I missing something about
NSManagedObject being different in some way from other classes?

Thanks very much for any help on this.


– Christos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160918/29ffbef6/attachment.html>


More information about the swift-users mailing list