EDIT: 19.02.2019 I tried the solutions offered. I went for a simpler option of passing a dictionary as the parameter and using Alamofire's JSONEncoder to turn it into a JSON object. This was the first thing I had tried but the problem was that Thanks everyone for the help.
I want to post a class object to an api but I'm struggling with types and encoding it to JSON.
let jsonData = try JSONEncoder().encode(classObject)
let params = String(data: jsonData, encoding: .utf8)
Alamofire.request(shopSubmitURL, method: .post, parameters: params).responseString { response in
switch(response.result) {
case .success(_) :
if let data = response.result.value {
print("Successfully submitted class object: \(response.result.value)")
}
break
case .failure(_):
print(response.result.error)
break
}
And my classObject is set up like this:
class classObject: NSObject, Codable {
var name : String = ""
var items : Array = [Int]()
}
I've tried converting the object to a dictionary with an extension but when I do I have to use 'Any' or 'AnyObject' and that causes 'cannot infer generic parameter' errors.
At the moment I get the 'extra argument 'method' in call' error.