'kUTTypeJPEG' is deprecated: first deprecated in macOS 12.0 - Use UTTypeJPEG

Updating to MacOS 12, in Objective C, I get the above warning regarding changing kUTTypeJPEG to UTTypeJPEG in two places The old code still works but even after the @import UniformTypeIdentifiers changing kUTTypeJPEG to UTTypeJPEG with various types, e.g. CFString, CFStringRef, and that UTTYPE doesn't bridge???, etc. (I am obviously clueless about this) I get the compiler warnings to go away but then the program crashes.

How do I fix these? Something to do with ARC or bridging???

CGImageDestinationRef destinationRef = CGImageDestinationCreateWithURL((__bridge CFURLRef)theURL, (NSString *)kUTTypeJPEG, 1, NULL);
NSDictionary *imageSourceCreationOptions = [NSDictionary dictionaryWithObjectsAndKeys:
                                                kUTTypeJPEG,(NSString *)kCGImageSourceTypeIdentifierHint,
                                                (NSNumber *)kCFBooleanTrue, (NSString *)kCGImageSourceShouldCache,
                                                (NSNumber *)kCFBooleanTrue, (NSString *)kCGImageSourceShouldAllowFloat,
                                                nil];

Accepted Reply

You were so close! Just have to call the identifier method on UTTypeJPEG.

CGImageDestinationRef destinationRef = CGImageDestinationCreateWithURL((__bridge CFURLRef)theURL, (__bridge CFStringRef)UTTypeJPEG.identifier , 1, NULL);

Replies

You were so close! Just have to call the identifier method on UTTypeJPEG.

CGImageDestinationRef destinationRef = CGImageDestinationCreateWithURL((__bridge CFURLRef)theURL, (__bridge CFStringRef)UTTypeJPEG.identifier , 1, NULL);

Yes, thank you ZackJarret. I had that ".identifier" in one permutation but not with (__bridge CFStringRef) (because I got another warning saying it could not bridge or something earlier - again I'm clueless).

And in the dictionary code, adding ".identifier" as a simple NSString was enough to make it all work.

FWIW, I did try chatGPT with three goarounds and finally it came up comments below. I'm glad you're human.

In recent macOS SDKs, UTTypeJPEG is deprecated, and you should use kUTTypeJPEG instead. If you're seeing a warning, it's generally safe to ignore it in this case because kUTTypeJPEG is the correct constant to use on macOS.

#pragma clang diagnostic ignored "-Wdeprecated-declarations"

CGImageDestinationRef destinationRef = CGImageDestinationCreateWithURL((__bridge CFURLRef)theURL, kUTTypeJPEG, 1, NULL);

#pragma clang diagnostic pop
Add a Comment