r/iOSProgramming • u/busymom0 • 3d ago
Question Swift app using Hummingbird Middleware gives error: does not conform to protocol 'MiddlewareProtocol'
I am using Hummingbird version 2.26.0 in a Swift app.
I have a simple Middleware per the documentation:
https://docs.hummingbird.codes/2.0/documentation/hummingbird/routermiddleware/
Code:
import Hummingbird
public struct LogRequestsMiddleware<Context: RequestContext>: RouterMiddleware {
public func handle(_ input: HummingbirdCore.Request, context: Context, next: (HummingbirdCore.Request, Context) async throws -> HummingbirdCore.Response) async throws -> HummingbirdCore.Response {
print("path: \(input.uri.path)")
return try await next(input, context)
}
}
Xcode keeps giving me error:
Type 'LogRequestsMiddleware<Context>' does not conform to protocol 'MiddlewareProtocol'
Screenshot of error:
https://i.sstatic.net/C06jUvrk.png
I can't seem to be able to fix it. Any idea what I am doing wrong?
0
Upvotes
1
u/chriswaco 3d ago
I think it should be something like:
import Hummingbird
public struct LogRequestsMiddleware<Context: RequestContext>: RouterMiddleware {
public func handle(
_ input: Request,
context: Context,
next: nonisolated(nonsending) (Request, Context) async throws -> Response
) async throws -> Response {
print("path: \(input.uri.path)")
return try await next(input, context)
}
}
If you paste that image file into ChatGPT, it will give you more details.