下面的
Swift 2示例给出了以下错误:
Value of type String has no member ‘stringByAppendingPathComponent’
我需要为Swift 3更改什么?
Apple试图将所有人从URL-as-string范例转移到URL(即file:///path/to/file.text). Swift API几乎删除了所有支持URL的路径.
你仍然可以在Objective-C(NSString)中找到它:
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask,true)[0] as String let getImagePath = NSString.path(withComponents: [paths,"fileName"])
Swifty方式越多:
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory,true)[0] as String let url = URL(fileURLWithPath: paths).appendingPathComponent("fileName")