My situation is similar to this below question related to .Net.
Value of type 'T' cannot be converted to TServiceResponse is My Code:
public class TServiceResponse : ResponseNode,CommsObject{
public var type : String!
public var Status : String?
required public init?(_ dictionary: NSDictionary){
self.type = dictionary.field("$type")
self.Status = dictionary.field("Status")
}
}
public enum WebResult<T : ResponseNode> {
case Result(JsonResponse<T>)
case Error(NSError)
}
func executePost<Message : RequestMessage, Node : ResponseNode>(request: JsonPostRequest<Message>,
completionHandler: (result: WebResult<Node>) -> Void) -> NSURLSessionTask?{
if let jsonResponse : JsonResponse<TServiceResponse> = self.createResponse(data, error: &runtimeError){
return completionHandler(result: (jsonResponse as? WebResult<Node>)!)
}
}
I believe that what I ask for defeats the purpose of the Generics in the first place. But is there a hack to get this done? I need this hack to ensure that I do minimum changes to the code.