I've come across a problem and I'm struggling to understand why this happens. Whenever I try and pass my custom Swift error object using generics, I get an error when I try to access the localizedDescription
property. I have some example code here, which demonstrates the issue:
import Foundation
enum CustomError: Swift.Error {
case myCustomError
var localizedDescription: String {
return "Woop custom error string"
}
}
func printMyError<T: Swift.Error>(error: T) {
print(error.localizedDescription)
}
printMyError(error: CustomError.myCustomError) // <-- Fails
print(CustomError.myCustomError.localizedDescription) // <-- Works