URL(fileURLWithPath
一起
absoluteString
是错的。
你必须写(注意不同的
URL
初始化器):
let imgPath = URL(string: documentDirectoryPath.appendingPathComponent("studioframe\(savedImageCount).jpg").absoluteString)
但是这个(
统一资源定位地址
艾斯
String
艾斯
统一资源定位地址
)非常麻烦,有一个更简单的解决方案,请考虑(字符串)路径和URL之间的区别
let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! // the Documents directory is guaranteed to exist.
let imgURL = documentDirectoryURL.appendingPathComponent("studioframe\(savedImageCount).jpg")
...
try data.write(to: imgURL, options: .atomic)