I've a mutable dictionary (in form of [Int:Int]) and want that to save it. I would use NSUserDefaults like that:
var myDic: NSMutableDictionary = [:]
myDic = [1:2]
NSUserDefaults.standardUserDefaults().setObject(myDic, forKey: "myDic")
but with that I get an error:
Thread 1: signal SIGABRT
I have no idea why.
setObject(_:forKey:)
can’t acceptDictionary
with a key which is integer type. The method requires property-list objects, butmyDic = [1:2]
is not property-list object.There are two documents about it.
setObject(_:forKey:) of NSUserDefaults
About Property Lists
If you set a integer-key to
Dictionary
, theDictionary
object cannot be used for a value ofsetObject
. You have to use a string for the key like this: