简体   繁体   English

如何在NSUserDefaults中设置数组的数组?

[英]How do I set an array of arrays in NSUserDefaults?

I want to set an array of arrays with NSUserDefaults like this: 我想用NSUserDefaults这样设置一个数组数组:

let array = [["Mexico","USA","Canada"],["Mexico City","Washington","Ottawa"]]

NSUserDefaults.standardUserDefaults().setObject(array, forKey:"Countries")

Then I try to access it 然后我尝试访问它

var recalledArray = NSUserDefaults.standardUserDefaults().objectForKey("Countries") as! NSArray
println(recalledArray)

But this is what the console prints: 但这是控制台显示的内容:

(
    "\U00bfMexico",
    "\U00bfUSA",
    "Canada"
)

I only get the first array, missing the second one: 我只得到第一个数组,而缺少第二个数组:

["Mexico City","Washington","Ottawa"]

Why am I only getting back the first array? 为什么我只找回第一个数组? How do I get back both the arrays? 我如何取回两个阵列?

我很抱歉,还有另一个问题,我正在检查应用程序是否首先启动,然后如果没有保存则保存NSUserDefaults,然后不要再次保存它,因此我在模拟器上运行应用程序后添加了第二个数组,因此代码从未保存到NSUserDefaults ,但无论如何,谢谢您的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM