Why can't I use jpegData(compressionQuality:) and pngData()?

Why am I not able to use jpegData(compressionQuality:) and pngData() instance methods of the UIImage class like the documentation says I can.

Accepted Reply

I'm looking at the documentation for UIImage under Instance Methods at Apple's website.


Then the documentaton is for Xcode 10 beta 3.

func jpegData(compressionQuality: CGFloat) -> Data?

You can find a sign showing "API changes Show" at the top-right of the page. When you click it you can see how it has changed since Xcode 9.4.


You need to use the global function (not an insance method) `

UIImageJPEGRepresentation(_:_:)` or `UIImagePNGRepresentation(_:)`, in Xcode 9.4.1.

Replies

Your question seems like a regression given how long you've been here.


Describe 'not able'?


What did you expect, what happened, exactly, how those two differed.

Maybe you are watching the documentation of Xcode 10 beta. Are you using Xcode 10 beta?

I'm looking at the documentation for UIImage under Instance Methods at Apple's website.

I'm using Xcode 9.4.1.

I'm looking at the documentation for UIImage under Instance Methods at Apple's website.


Then the documentaton is for Xcode 10 beta 3.

func jpegData(compressionQuality: CGFloat) -> Data?

You can find a sign showing "API changes Show" at the top-right of the page. When you click it you can see how it has changed since Xcode 9.4.


You need to use the global function (not an insance method) `

UIImageJPEGRepresentation(_:_:)` or `UIImagePNGRepresentation(_:)`, in Xcode 9.4.1.

I have Xcode Version 10.1 (10B61). This line of code:


let _ = UIImage().jpegData(compressionQuality: 1.0)


causes this error:


'jpegData(compressionQuality:)' has been renamed to 'UIImageJPEGRepresentation(_:_:)'

Replace 'jpegData' with 'UIImageJPEGRepresentation'

Sorry, but I cannot reproduce the same issue with my Xcode 10.1 (10B61).

But I recommend you to start a new thread for your own. Not many readers take care of a comment in a SOLVED thread.