This is an extension of the question : creating-a-function-on-a-parent-class-that-can-be-accessible-to-all-its-children
It was suggested instead of using a class for a function a protocol would be better. After attempting the protocol approach the error "Protocol type 'JSONObject ' cannot be instantiated" happens. Any help in fixing this error is appreciated. Here is the protocol:
protocol JSONObject: class, NSObjectProtocol { init(resultsDictionary: [String:Any]) } extension JSONObject { static func updateResultsDictionary(urlExtension: String, completion: @escaping (JSONObject?) -> Void) { let nm = NetworkManager.sharedManager _ = nm.getJSONData(urlExtension: urlExtension) {data in guard let jsonDictionary = nm.parseJSONFromData(data), let resultDictionaries = jsonDictionary["result"] as? [[String : Any]] else { completion(nil) return } for resultsDictionary in resultDictionaries { let jsonInfo = JSONObject(resultsDictionary: resultsDictionary)// Error haapens here completion(jsonInfo) } } } }