Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'Error' does not conform to protocol 'RawRepresentable'

Changing my playground code to Swift 3, Xcode suggested changing

enum Error: ErrorType {
    case NotFound
}

to

enum Error: Error {
    case NotFound
}

but now I get the title error and I don't know how to get the enum to conform to that protocol.

like image 931
Shades Avatar asked Sep 10 '16 21:09

Shades


2 Answers

The problem is that you've named your error type Error – which conflicts with the standard library Error protocol (therefore Swift thinks you've got a circular reference).

You could refer to the Swift Error protocol as Swift.Error in order to disambiguate:

enum Error : Swift.Error {
    case NotFound
}

But this will mean that any future references to Error in your module will refer to your Error type, not the Swift Error protocol (you'll have to disambiguate again).

Therefore the easiest solution by far would be simply renaming your error type to something more descriptive.

like image 101
Hamish Avatar answered Oct 01 '22 04:10

Hamish


This error occurs because you are "overriding" the existing declaration ofError which is a protocol. So you have to choose another (probably more descriptive) name for your "Error" enum.

like image 35
Qbyte Avatar answered Oct 01 '22 02:10

Qbyte