Jonathan
Jonathan

Reputation: 686

Why am I getting a "Function is unused" error?

I'm trying to unit test a closure that works just fine, but for whatever reason the compiler throws this Function is unused error in the test. I'm passing the parameter. What am I missing?

enter image description here

This is the closure's definition:

configuration.router.didSelectProduct = { navigationController in
    { product in
      let vc = More.build(navigationController: navigationController)
      navigationController.pushViewController(vc, animated: true)
    }
  }

Note that the closure variable is optional so I'm force unwrapping it for simplicity.

Upvotes: 1

Views: 370

Answers (1)

Ranoiaetep
Ranoiaetep

Reputation: 6637

The problem with your code is that didSelectProduct is a nested closure, and you are missing the parameter for the inner closure. You can provide a second parameter like:

didSelectProduct!(navController)(someProduct)

Upvotes: 2

Related Questions