【发布时间】:2015-12-07 14:03:27
【问题描述】:
我正在创建一个 plist,我想在其中保存某些数据。我有一本需要写在文件中的字典。字典有一个用于值的名称数组和一个用于键的键数组 b。但我不知道我在哪里做错了,但我的代码不起作用。
let namearray = [self.usernametextfield.text,self.passwordtextfield.text]
let keyarray = ["username","password"]
let dict = NSMutableDictionary()
dict.setObject(namearray as! AnyObject, forKey: keyarray) // I am having problem in this line of how to add arrays to dictionary.
dict .writeToFile(plistfinalpath, atomically: true)
那么任何人都可以建议如何将数组作为键和值添加到字典中。请更正我的代码。
【问题讨论】:
-
来自aaisataev:你可以用swift重写它-NSDictionary containing an NSArray
标签: arrays swift dictionary ios9 plist