简体   繁体   中英

Error trying to upload an image to CloudKit using Swift3

I'm running into a compiler error when using the following code:

func saveImageToDisk() {

    let imageData = UIImagePNGRepresentation(imageView.image!)!
    let fileName = getDocumentsDirectory().appendingPathComponent("image.png")
    imageData.writeToFile(fileName, atomically: true)

}

The error is: Value of type 'Data' has no member 'writeToFile'

Could this be a compiler error, or something I'm missing? Thanks

SE-0005 proposed a better translation of Objective-C APIs into Swift and that affected NSData (or just Data now). Instead of writeToFile you'll have to use write(to:options:) (or even just write(to:) ). Here is the documentation for the updated method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM