I have this function:
class myClass: ObservableObject {
func doSomethingElse<T:Decodable>(url: URL,
config: URLSessionConfiguration,
type: T.Type) -> AnyPublisher<Int, any Error> {
return URLSession(configuration:config).dataTaskPublisher(for: url)
.tryMap{ response in
guard let valueResponse = response.response as? HTTPURLResponse else {
return 000
}
return valueResponse.statusCode
}.mapError{error in
return error
}
.eraseToAnyPublisher()
}
}
and it works just fine but I'm trying to add this function to URLSession extension:
extension URLSession {
func doSomethingElse<T:Decodable>(url: URL,
config: URLSessionConfiguration,
type: T.Type) -> AnyPublisher<Int, any Error> {
return self(configuration:config).dataTaskPublisher(for: url)
.tryMap{ response in
guard let valueResponse = response.response as? HTTPURLResponse else {
return 000
}
return valueResponse.statusCode
}.mapError{error in
return error
}
.eraseToAnyPublisher()
}
But I'm getting this error:
Cannot call value of non-function type 'URLSession'
Any of you knows why I'm getting this error? or how can configure URLSession to have the configuration?
I'll really appreciate your help

selfis the specific instance ofURLSession. You wantSelf, which is the typeYou may also want
doSomethingElseto be astaticfunction, since it doesn't actually reference the specific instance ofself: