let plistPath = NSBundle.mainBundle().pathForResource("userConfig", ofType: "plist")
let dict = NSMutableDictionary(contentsOfFile: plistPath)
let data: (AnyObject!) = dict.objectForKey("baiduUrl")
var myDictionary: String = "http://www.baidu.com"
myDictionary.setObject(plistPath, forKey: "baiduUrl")
myDictionary.writeToFile(plistPath, atomically: false)
println(myDictionary)
错误:“字符串”没有名为“ setObject”的成员
更改编码。我无法更改plist
var myDictionary: String = "http://www.baidu.com" // You say you have an String called myDictionary, not a dictionary
myDictionary.setObject(plistPath, forKey: "baiduUrl") // myDictionary is a String, so you can't set any object to it.
您需要做的是(未试过的相关部分)
let myString:String = "http://www.baidu.com"
var myMutableDictionary = NSMutableDictionary()
myDictionary.setObject(myString, forKey:"baiduUrl")
或者,如果您的字典是不可变的,则可以将其创建为NSDictionary,直接将myString分配给您的键。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句