Cannot invoke 'decode' with an argument list of type '(T, from: Data)'

a 夏天 提交于 2019-12-01 10:30:35

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) { ... }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!