extension NSImage{

func cgImage() -> CGImage{
let data = self.tiffRepresentation
var imageRef : CGImage!
var sourceRef : CGImageSource!

sourceRef = CGImageSourceCreateWithData(data! as CFData, nil)
if (sourceRef != nil) {
imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, nil)
}
return imageRef
}
}
