title: Swift NSImage to CGImage
body: <p>How can I convert a NSImage to CGImage in Swift? In Objective-C I did it like this:</p>
  
  <pre><code>- (CGImageRef)CGImage {
      NSData *imageData = self.TIFFRepresentation;
      CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
      CGImageRef maskRef =  CGImageSourceCreateImageAtIndex(source, 0, NULL);
      return maskRef;
  }
  </code></pre>
  
  <p>Now I tried with:</p>
  
  <pre><code>extension NSImage {
      var CGImage: CGImageRef {
      get {
          let imageData = self.TIFFRepresentation
          let source = CGImageSourceCreateWithData(imageData as CFDataRef, nil)
          let maskRef = CGImageSourceCreateImageAtIndex(source, UInt(0), nil)
          return maskRef;
      }
      }
  }
  </code></pre>
  
  <p>I can't compile, I'm getting the error: <code>Could not find an overload for 'init' that accepts the supplied arguments'</code> at the line <code>let maskRef ...</code></p>