Ambiguous reference to the init (from :) 'element for Enum

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:)' 

enter image description here

 /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) } } 
+7
enums swift
source share
2 answers

I had the same problem using Xcode 9.2 beta (9C32c), if this is an error, it still is not fixed in this version. I found a workaround for the error to disappear without overriding init .

I changed this:

  NumberEnumSpecial.init(rawValue: 2) 

:

  NumberEnumSpecial(rawValue: 2) 
+19
source share

This is not an answer, but I realized that they work correctly if you declare them in the same file that uses them. There may be a mistake, there may be a key ...

0
source share

All Articles