CGImageDestinationCreateWithData constants in iOS

I have the following code that turns a CGImageinto NSData:

import Foundation
import CoreGraphics
import ImageIO
// ... snip ...
    let data = NSMutableData()
    if let dest = CGImageDestinationCreateWithData(data, kUTTypePNG, 1, nil), let image = self.backgroundImage {
        CGImageDestinationAddImage(dest, image, nil)
        if CGImageDestinationFinalize(dest) {
            return data as Data
        }
    }
    return nil

The code compiles on Mac OS, but kUTTypePNGis undefined on iOS. The actual value of the constant "public.png", and, obviously, replacing the constant with this value allows iOS to compile the code in order.

But avoiding magic strings / numbers, we use constants in the first place - is there an alternative constant in Swift-iOS?

0
source share
1 answer

From the Basics of Mobile Services to iOS Technology Overview:

(MobileCoreServices.framework) , (UTI).

, , . .

,

import MobileCoreServices

public let kUTTypePNG: CFString

UTI, .

+3

Source: https://habr.com/ru/post/1652616/


All Articles