Compress Image in iOS 12. How will this code be updated? [duplicate]

假装没事ソ 提交于 2019-12-17 10:00:08

问题


// compressing image(avaImg)before sending it to the server(Parse)

let avaData = UIImageJPEGRepresentation(avaImg.image!, 0.5)
    let avaFile = PFFile(name: "ava.jpg", data: avaData!)
    user["ava"] = avaFile

When I replace it to the following line as recommended by the notifications I get the error below

let avaData = UIImage.jpegData(avaImg.image!, 0.5)

ERROR: Instance member 'jpegData' cannot be used on type 'UIImage'; did you mean to use a value of this type instead?

I'm a newbie and I followed that on an online course so please baby steps!


回答1:


Do you mean swift 4.2? Call it like this yourImageObject.jpegData(compressionQuality: 0.5) because function changed to public func jpegData(compressionQuality: CGFloat) -> Data? For more syntax I have a repo you can take a reference with changes from swift 4. https://github.com/alexliubj/Swift-Migration-4.2

Updated: This API change is from iOS 12, not Swift 4.2. Thanks @rmaddy for your correction.



来源:https://stackoverflow.com/questions/52116351/compress-image-in-ios-12-how-will-this-code-be-updated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!