title: CGImageDestinationCreateWithData constants in iOS
body: <p>I have the following code which turns a <code>CGImage</code> into <code>NSData</code>:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>The code compiles fine in Mac-OS, but <code>kUTTypePNG</code> is undefined in iOS. The actual value of the constant is <code>"public.png"</code>, and obviously, replacing the constant with that value allows iOS to compile the code fine. </p>
  
  <p>But avoiding magic strings/numbers is the reason we use constants in the first place - is there an alternative constant in Swift-iOS?   </p>