Moya: Xcode error with new requestClosure in 7.0
My request closure looks like this:
let requestClosure = { (endpoint: Moya.Endpoint<ICanHazProvider>, done: Result<NSURLRequest, Moya.Error> -> Void) in
let request = endpoint.urlRequest.mutableCopy() as! NSMutableURLRequest
if let token = self.getToken() {
request.setValue(token, forHTTPHeaderField: "token")
}
return done(.Success(request))
}
hazAPI = MoyaProvider<ICanHazProvider>(endpointClosure: endpointClosure, requestClosure: requestClosure)
I’m getting the following error in Xcode now:
Unable to infer closure return type in current context
Is there any secret to getting this to work?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 20 (8 by maintainers)
@ashfurrow Well, as I was preparing the example project, I realized that if I omit the variable type declarations in the closure it seems to compile and work fine. So I changed
to
So - the issue is really weird. If you do:
Everything is peachy. If you pass all the parameters, even if you copy them from the default implementation of
init
it gets the above result. So:@sunshinejr omitting the
Result
type did the trick, thanks!I should clarify a bit: Error is on the next line: