Ambiguous reference to member '=='

17,619

The error message is misleading. The problem is that the compiler has no information what type the values .Zero, .NotZero refer to.

The problem is also unrelated to managed objects or the valueForKey method, you would get the same error message for

func foo(value: Int) {
    let eltType = value == 0 ? .Zero : .NotZero // Ambiguous reference to member '=='
    // ...
}

The problem can be solved by specifying a fully typed value

let eltType = value == 0 ? MyEnum.Zero : .NotZero

or by providing a context from which the compiler can infer the type:

let eltType: MyEnum = value == 0 ? .Zero : .NotZero
Share:
17,619
Michel
Author by

Michel

I am currently developing iOS software, mainly using Swift. With a total of about 20 apps on the appStore, the main ones being related to language learning. For some examples see: http://www.sofisfun.net/Language/ and http://www.sofisfun.net/Calculators/ I recently got to work on Heroku to port some projects from the Parse.com site to open source Parse-Server, that got me on the way to get my hands on Node.JS where I built this little prime number site to get familiar with the environment. And I more recently got interested in Clojure, where I built this as a trial project.

Updated on June 14, 2022

Comments

  • Michel
    Michel almost 2 years

    That must be a basic mistake, but I can't see what is wrong in this code:

    .... object is some NSManagedObject ....
    let eltType = ((object.valueForKey("type")! as! Int) == 0) ? .Zero : .NotZero
    

    At compile time, I get this message:

    Ambiguous reference to member '=='
    

    Comparing an Int to 0 doesn't seem ambiguous to me, so what am I missing?