简单的先存再取一个一个数组,然后数组里有一个dictionary
let dict1 = ["1":1,"2":2,"3":"3"]
let array1 = [ dict1 , dict1 , dict1 , dict1 ]
NSUserDefaults.standardUserDefaults().setObject(array1, forKey : "animals" )
NSUserDefaults.standardUserDefaults().synchronize ()
let animals = NSUserDefaults .standardUserDefaults().objectForKey ( "animals" )
print( "We saved this data: \( animals )" )
简单的先取,再存一个数组,然后数组里有一个dictionary
let userDefaults = NSUserDefaults.standardUserDefaults()
var arr = [[String: String]()]
if let a = userDefaults.objectForKey("commonfile") {
arr = a as! [[String : String]]
}
else{
arr = []
}
let dict = ["name":"1","time":"2016-03-15","totaltime":"02:48"]
arr+=[dict]
userDefaults .setObject(arr, forKey: "commonfile")
userDefaults.synchronize()