valid replacement for kUTTypeJPEG which is deprecated

I have the following code:

let ciImage = filterAndRender(ciImage: inputImage, doCrop: true)

        let outCGImage = ciContext.createCGImage(ciImage, from: ciImage.extent)!

        let dest = CGImageDestinationCreateWithURL(output.renderedContentURL as CFURL, kUTTypeJPEG, 1, nil)!

        CGImageDestinationAddImage(dest, outCGImage, [kCGImageDestinationLossyCompressionQuality as String:1] as CFDictionary)

        CGImageDestinationFinalize(dest)

I get the following caution: " 'kUTTypeJPEG' was deprecated in iOS 15.0: Use UTTypeJPEG instead."

However, when I substitute 'UTTypeJPEG' as directed, I get this error: "Cannot find 'UTTypeJPEG' in scope"

What should I use for kUTTypeJPEG instead?

Thanks!

Replies

Seems the deprecation message is meant for Objective-C code. (You can send a bug report to Apple using Feedback Assistant.)

In Swift, Uniform Type Identifiers are wrapped into static members of UTType.

System Declared Uniform Type Identifiers

Can you try UTType.jpeg.identifier as CFString instead?

(You may need import UniformTypeIdentifiers if your source code does not have it yet.)

The same here for :

        kUTTypeFileURL 

        kUTTypeUTF8PlainText

despite import :

import MobileCoreServices
import UniformTypeIdentifiers

the error :

'kUTTypeFileURL' was deprecated in iOS 15.0: Use UTTypeFileURL instead.

'kUTTypeUTF8PlainText' was deprecated in iOS 15.0: Use UTTypeUTF8PlainText instead.

Posting a link this thread for the benefit of those reading along at home.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

So, I had a similar circular warning for this same method where I wanted to identify a JPG or a PNG image and create an image with the appropriate extension. Although a good example of how to use it was not clear to me and here's what worked for me (Objective C).

  1. Import the newer identifiers:
@import UniformTypeIdentifiers;
  1. Create a property to hold the identifiers:
@property (strong) NSString *imageType;
  1. Assign one of the identifiers to the property:
if ([theImageExtension isEqualToString:@"png"]) {

        _imageType = (NSString *)UTTypePNG.identifier;

    } else {

        _imageType = (NSString *)UTTypeJPEG.identifier;
    }
  1. Use it:
CGImageDestinationRef destinationRef = CGImageDestinationCreateWithURL((__bridge CFURLRef)theURL, (CFStringRef)_imageType, 1, NULL);

And that worked! (after many permutations)