我在使用以下代码时遇到编译器错误:
func saveImageToDisk() {
let imageData = UIImagePNGRepresentation(imageView.image!)!
let fileName = getDocumentsDirectory().appendingPathComponent("image.png")
imageData.writeToFile(fileName, atomically: true)
}
错误是:“Data”类型的值没有成员“writeToFile”
这可能是编译器错误,还是我遗漏了什么?谢谢
最佳答案
SE-0005提议将 Objective-C API 更好地转换为 Swift,这影响了 NSData(或现在只是 Data)。您必须使用 write(to:options:)
(甚至只是 write(to:)
),而不是 writeToFile
。 Here是更新方法的文档。
关于ios - 尝试使用 Swift3 将图像上传到 CloudKit 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38131519/