下面的 Swift 2 示例给出了此错误:
String 类型的值没有成员“stringByAppendingPathComponent”
对于 Swift 3,我需要更改什么?
Apple 正试图让所有人摆脱路径字符串范式,转向 URL(即file:///path/to/file.text
)。 Swift API 几乎删除了所有path
有利于URL
.
你仍然可以在 Objective-C 中找到它(NSString
):
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let getImagePath = NSString.path(withComponents: [paths, "fileName"])
更迅速的方式:
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let url = URL(fileURLWithPath: paths).appendingPathComponent("fileName")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)