下面的Swift 2示例给出了以下错误:
String类型的值没有成员'stringByAppendingPathComponent'
我需要为Swift 3更改什么?
Apple试图将所有人从URL(即file:///path/to/file.text
)的路径范式转移到URL(即).Swift API几乎完全取消path
了URL
.
你仍然可以在Objective-C(NSString
)中找到它:
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let getImagePath = NSString.path(withComponents: [paths, "fileName"])
Run Code Online (Sandbox Code Playgroud)
Swifty方式越多:
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let url = URL(fileURLWithPath: paths).appendingPathComponent("fileName")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4863 次 |
最近记录: |