Why does the following code give me the error:
Invalid type in JSON write (_SwiftValue).
The error is thrown on this line:
If you're using SwiftyJSON to access a JSON object, it's important to use the dictionaryObject
property of the JSON (instead of using dictionaryValue
, dictionary
or nothing at all), because you will get this error (or a variation of it) otherwise. For example:
guard let jsonDict = json.dictionaryObject else {
return
}
let jsonData = try JSONSerialization.data(withJSONObject: jsonDict, options: [])