Hãy nói rằng chúng tôi có Enum này:tham khảo mơ hồ thành viên 'init (từ :)' cho Enum
enum NumberEnumSpecial: Int32 {
case two = 2, three = 3
}
Tôi muốn init nó với một Int32, vì vậy tôi sử dụng này:
let myEnum = NumberEnumSpecial.init(rawValue: 2)
Điều này hoạt động trong một dự án sân chơi nhưng không có trong dự án ứng dụng thông thường của tôi. Tôi nhận được lỗi này cho mã chính xác như nhau:
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
Nhấp vào các ứng cử viên không có tác dụng.
Nếu bạn hỏi tôi có vẻ như là một Enum ở đâu đó trong mã với việc triển khai init (từ) gây ra lỗi này trên Enum của tôi. Nhưng tìm kiếm văn bản này cho tôi không có kết quả.
Lỗi này là gì và làm cách nào để tìm hiểu nguyên nhân gây ra lỗi này?
Sử dụng Swift 3.2 và XCode9.0
Hiện nay workaround:
enum NumberEnumSpecial: Int32 {
case two = 2, three = 3
init?(withSpecialNumber number : Int32) {
self.init(rawValue: number)
}
}
Không thể sinh sản. Bạn có thể hiển thị thông báo lỗi trình biên dịch đầy đủ từ trình điều hướng Báo cáo không? –
Nên có một nút ở đầu bên phải của dòng "Biên dịch DangerZone.swift" để hiển thị các thông điệp trình biên dịch dưới dạng * văn bản. * - Hiển thị văn bản đó chứ không phải ảnh chụp màn hình. –
Nhật ký đầy đủ: https://pastebin.com/18VigRqw –