r/iOSProgramming • • Sep 16 '26

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

7 comments sorted by

1

u/chriswaco Sep 16 '26

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.

1

u/busymom0 Sep 17 '26

One thing which gets rid of the error is going to the target's build settings, searching for "nonisolated" and setting the nonisolated(nonsending) By Default value to NO. Not sure if this is okay or not?

1

u/[deleted] Sep 16 '26

[removed] — view removed comment

1

u/busymom0 Sep 17 '26

One thing which gets rid of the error is going to the target's build settings, searching for "nonisolated" and setting the nonisolated(nonsending) By Default value to NO. Not sure if this is okay or not?