I am following John Sundell's post (https://www.swiftbysundell.com/posts/providing-a-unified-swift-error-api) on using a nice perform
function to create a unified error API
func perform(_ expression: @autoclosure () throws -> T,
orThrow error: Error) throws -> T {
do {
return try expression()
} catch {
throw error
}
}
func someFunction(url: URL) throws -> Data {
...
return try perform(Data(contentsOf: url),
orThrow: SearchError.dataLoadingFailed(url))
}
But it gives me Use of undeclared type
error at T
. Isn't Xcode supposed to figure out type T by looking at the return type of the function passed in?
You need to declare any type parameters used in your function signature: