Say we have this listing:
enum NumberEnumSpecial: Int32 { case two = 2, three = 3 }
I would like to initialize it using 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 get this error for the 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 candidates does not affect.
If you ask me, it looks like Enum has some code that implements an init (from) implementation that causes this error in my Enum. But the search for this text does not give me any results.
What is this error and how to find out what causes it?
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) } }
enums swift
Sjoerd perfors
source share