how to set and later get array of json objects in UserDefaults
?
My application crashes when i try to set it as follow:
import SwiftyJSON
var finalArray = [JSON]()
UserDefaults.standard.set(finalArray, forKey: "attemptedArray")
my data looks like:
[{
"marked" : 3,
"attempted" : true,
"correct" : 3,
"subject" : 1,
"status" : true,
"question" : 219,
"answer" : 32931,
"time" : 15,
"score" : 5,
"chapter" : 26
}, {
"marked" : 4,
"attempted" : true,
"correct" : 4,
"subject" : 1,
"status" : true,
"question" : 550,
"answer" : 34256,
"time" : 23,
"score" : 10,
"chapter" : 26
}, {
"marked" : 1,
"attempted" : true,
"correct" : 1,
"subject" : 1,
"status" : true,
"question" : 566,
"answer" : 34317,
"time" : 33,
"score" : 14,
"chapter" : 26
}]