You want to pass type of struct, not protocol.
First, make generic constraint for your method which says that T has to conform to Decodable (since you need it just for decoding, you don’t need conforming to Encodable)
Then say that parameter should be of type T.Type - this allows compiler to infer type of T, you can avoid using this parameter, see at the end of the answer
static func Get<T: Decodable>(codePoint: String, responseType: T.Type) { ... }
... so T will be type which you'll pass to method.
Then for JSONDecoder's decode method use type of T
JSONDecoder().decode(T.self, from: data)
and then when you want to call your method, pass type of your struct like you did it within decoding
HttpRequests.Get(codePoint: "getCategoryList", responseType: Category.self)
Also note that your call is async so for returning data you'll need completion handler defined as parameter of your method
completion: @escaping (T?) -> Void
note that names of methods should start with small capital letters
static func get<T: Decodable>(codePoint: String, responseType: T.Type, completion: @escaping (T?) -> Void) {
let urlString = UrlUtils.GetUrl(codePoint: codePoint)
let url = URL(string: urlString)
URLSession.shared.dataTask(with: url!) { data, response, error in
guard let data = data else {
print(error!)
return completion(nil)
}
do {
let decoded = try JSONDecoder().decode(T.self, from: data)
completion(decoded)
} catch {
print(error)
completion(nil)
}
}.resume()
}
HttpRequests.get(codePoint: "getCategoryList", responseType: Category.self) { response in
if let category = response {
...
}
}
You can also avoid using responseType parameter since type of T can be inferred from the type of parameter of completion closure
static func get<T: Codable>(codePoint: String, completion: @escaping (T?) -> Void) { ... }
HttpRequests.get(codePoint: "getCategoryList") { (category: Category?) -> Void in ... }