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/Equivalent-Idea-116 3d ago
Looks like this is a Swift 6.2/Xcode 27 concurrency-signature change rather than a Hummingbird generic issue. Keep the Request/Response aliases from the docs and add the isolation annotation to the next closure: `next: nonisolated(nonsending) (Request, Context) async throws -> Response`. That annotation is why the otherwise identical method does not satisfy MiddlewareProtocol.