objective-c - Swift如何编写plist文件并更改值?

标签 objective-c xcode macos swift

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'

enter image description here

更改编码。我无法更改 plist enter image description here

最佳答案

您将 myDictionary 声明为字符串(并使用字符串文字对其进行初始化)。我很确定您打算将其声明为字典(给定名称)。字符串和字典不是一回事。

关于objective-c - Swift如何编写plist文件并更改值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25312365/

相关文章:

xcode - iOS- Storyboard -在 Storyboard 的配置面板中以编程方式使用定义的颜色

ios - Testflight 在 Mac OS X 桌面应用程序中找不到 SDK?

c - 为 Sublime Text 3 设置 C 编译器

python - 在 "OS X"上使用 Python ArgParse 的 UTF-8 STDIN+STDOUT

ios - 按 NSNumber 值对 NSDictionary 键进行排序

ios - MapKit pin不显示leftCalloutAccessoryView

iphone - 我的单元格中有一个我需要访问的按钮...我如何访问它?

swift - 无法更改导航栏高度 ios 11

objective-c - 如何从 UICollectionViewCell 继续推送到导航 Controller ?

ios - UIImages 像 Instagram 应用程序一样滚动