Thor
Thor

Reputation: 10048

when implementing ErrorProtocol, keep getting error 1) use of undeclared type ErrorProtocol 2) type does not conform to protocol RawRepresentable

I'm learning swift by following the swift programming lanuguage 3.0 handbook. In the error handling chapter, when one want to declare an error type, you implement the ErrorProtocol protocol. As shown below:

enum VendingMachineError: ErrorProtocol{
    case invalidSelection
    case insufficientFuns(coinsNeeded: Int)
    case outOfStock
}

But in xcode playground, I keep getting the error message

1) use of undeclared type ErrorProtocol

2) type VendingMachineError does not conform to protocol RawRepresentable

Why is this happening? I'm simply coping the code from the book.

enter image description here

Upvotes: 0

Views: 190

Answers (1)

Tj3n
Tj3n

Reputation: 9923

It's not ErrorProtocol, it's ErrorType, you declare that when creating error enum

Upvotes: 1

Related Questions