Reputation: 1333
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)
Error : 'String' does not have a member named 'setObject'
change coding.I can not change plist
Upvotes: 0
Views: 1985
Reputation: 579
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.
What you need to do is (untested, relevant part)
let myString:String = "http://www.baidu.com"
var myMutableDictionary = NSMutableDictionary()
myDictionary.setObject(myString, forKey:"baiduUrl")
Or if your dictionary will be inmutable you can create it as NSDictionary assigning directly the myString to your key.
Upvotes: 0
Reputation: 41831
You declared myDictionary as a String (and initialized it with a String literal). I'm pretty sure you meant to declare it as a Dictionary, given the name. Strings and Dictionaries are not the same thing.
Upvotes: 1