I'm implementing try catch enum:
enum processError: Error, CustomStringConvertible {
case one
var localizedDescription: String{
return "one"
}
case two
var localizedDescription: String {
return "two"
}
}
But I'm getting the following error:
type processError does not conform to protocol CustomStringConvertible
But if I change the name of the variable in the second case I don't get the error:
enum processError: Error, CustomStringConvertible {
case one
var localizedDescription: String{
return "one"
}
case two
var description: String {
return "two"
}
}
My question is why I can not have the same name of the variable for all the cases?
I'll really appreciate your help.
The issue is that the CustomStringConvertible protocol requires one property:
var description: String
You need to have the description property or you will get the error that it doesn't conform to the protocol.
I also suggest this approach:
enum processError: Error, CustomStringConvertible {
case one
case two
var description: String {
switch self {
case .one:
return "one"
case .two:
return "two"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With