func sendToServer(message: Codable) {
do {
let jsonData = try JSONEncoder().encode(message)
let jsonString = String(data: jsonData, encoding: .utf8)!
// send to server jsonString
} catch let error {
debugPrint("Error occured during parsing \(error.localizedDescription)")
}
}
I am trying to create a method which accepts objects which conform to Codable but I am getting this error when I am trying to encode:
Cannot invoke 'encode' with an argument list of type '(Codable)'
How can I write a method to achieve this?