You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The below mocked generic completion handler does not compile as the generic Value can not be found outside the function.
Current state:
protocolMyProtocol{func foo<Value:Codable>(completion:(Value)->Void)}classMyProtocolMock:MyProtocol{varinvokedFoo=falsevarinvokedFooCount=0varstubbedFooCompletionResult:(Value,Void)? // Value can not be found
func foo<Value:Codable>(completion:(Value)->Void){
invokedFoo =true
invokedFooCount +=1iflet result = stubbedFooCompletionResult {completion(result.0)}}}
Proposed solution:
protocolMyProtocol{func foo<Value:Codable>(completion:(Value)->Void)}classMyProtocolMock:MyProtocol{varinvokedFoo=falsevarinvokedFooCount=0varstubbedFooCompletionResult:(Any,Void)? // Change Value to Any
func foo<Value:Codable>(completion:(Value)->Void){
invokedFoo =true
invokedFooCount +=1iflet result = stubbedFooCompletionResult {completion(result.0as!Value) // Force cast as Value
}}}
Ideally the solution also covers more complex completion handlers, where the generic type is nested. E.x:
The below mocked generic completion handler does not compile as the generic
Value
can not be found outside the function.Current state:
Proposed solution:
Ideally the solution also covers more complex completion handlers, where the generic type is nested. E.x:
The text was updated successfully, but these errors were encountered: