Let's say we have this Enum:
enum NumberEnumSpecial: Int32 {
case two = 2, three = 3
}
I would like to init it with a Int32, so I use this:
let myEnum = NumberEnumSpecial.init(rawValue: 2)
This works in a playground project but not in my regular App project. I'm getting this error for the exact same code:
Ambiguous reference to member 'init(from:)'
/Users/sjoerd/GitHub/flitsmeister-ios/app/Flitsmeister7/Model/Melding/DangerZone.swift:91:22: error: ambiguous reference to member 'init(from:)'
let myEnum = NumberEnumSpecial.init(rawValue: 2)
^~~~~~~~~~~~~~~~~
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Swift.RawRepresentable:2:24: note: found this candidate
public convenience init(from decoder: Decoder) throws
^
Build failed 13/10/2017, 09:32
Clicking on the candidates has no effect.
If you ask me there seems to be a Enum somewhere in the code with an implementation for init(from) causing this error on my Enum. But searching for this text gives me no results.
What is this error and how can find out what is causing this ?
Using Swift 3.2 and XCode9.0
Currently workaround:
enum NumberEnumSpecial: Int32 {
case two = 2, three = 3
init?(withSpecialNumber number : Int32) {
self.init(rawValue: number)
}
}
I had the same problem using Xcode 9.2 beta (9C32c), if it is a bug it is still not fixed in this version. I found a workaround to make the error disappear without overriding the init
.
I changed this:
NumberEnumSpecial.init(rawValue: 2)
to this:
NumberEnumSpecial(rawValue: 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With