Why does the following code give me the error:
Invalid type in JSON write (_SwiftValue).
The error is thrown on this line:
I was getting this runtime error because my dictionary was like this:
var dictionary: [AnyHashable: Any] = [:]
let elapsedTime = Date.timeIntervalSince(oldDate)
dictionary["elapsedTime"] = elapsedTime
Can you tell me what the problem is? hover your mouse on the box below to see answer!
elapsedTime's type isFunctionit's notTimeInterval. I needed to changeDate.toDate().ie use the instance method rather than the static method. When you're dictionary values areAnythen this sort of issue doesn't get found until a runtime error where it can't serialize the dictionary to a JSON string...