【发布时间】:2015-10-16 17:36:43
【问题描述】:
在从 swift 转换为 swift 2.0 后,我已将所有应用程序的 Xcode 更新为 7,但经过一番研究后,我能够手动修复它们。
但是,我无法解决“stringByAppendingPathComponent”的错误。 swift 2.0 好像去掉了这个方法。
所附图片显示了我正在平铺的错误。
知道如何解决这个问题吗?
func loadNotes(){
let plistPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) as NSArray
let DocumentsDirectory = plistPath[0] as! String
let path = DocumentsDirectory.stringByAppendingPathComponent("notes.plist")
let fileManager = NSFileManager.defaultManager()
if (!fileManager.fileExistsAtPath(path)) {
if let bundlePath = NSBundle.mainBundle().pathForResource("notes", ofType: "plist") {
let resultDictionary = NSMutableDictionary(contentsOfFile: bundlePath)
println("Bundle notes.plist file is --> \(resultDictionary?.description)")
fileManager.copyItemAtPath(bundlePath, toPath: path, error: nil)
println("copy")
} else {
println("notes.plist not found")
}
}else {
println("note.plist already exists")
//fileManager.removeItemAtPath(path, error: nil)
}
let resultDictionary = NSMutableDictionary(contentsOfFile: path)
println("Loaded notes.plist file is --> \(resultDictionary?.description)")
var myDict = NSDictionary(contentsOfFile: path)
if let dict = myDict {
//load values
} else {
println("worning ccould not create dictionary from notes.plist, default values will be used")
}
}
【问题讨论】:
-
这是很多 swift 1.2 代码 - 没有更多的 println
-
尝试使用转换为最新的 swift 语法选项
-
嗨 Jeef 是的,我附上了 1.2 - 我尝试使用转换为最新的 swift 语法选项,但错误没有改变