I\'m trying to create a function that takes in a parameter of type \'Codable\' based on the custom JSON models being passed to it. The error :
Cannot invoke
The type of the type T
is its metatype T.Type
, therefore the
function parameter must be declared as type: T.Type
.
You may also want to make the completion handle take a parameter of type T
instead of Codable
:
static func updateDataModels <T : Codable> (url: serverUrl, type: T.Type,
completionHandler:@escaping (_ details: T) -> Void)
When calling the function, use .self
to pass the type as an
argument:
updateDataModels(url: ..., type: MainDataFamily.self) { ... }