tymac tymac - 4 months ago 119
Swift Question

Xcode 8 / Swift 3 - Type 'CGColorRenderingIntent' has no member 'RenderingIntentDefault'

I have an open-source Swift playground of an image tracer. I've successfully converted the 10 errors to Swift 3 except for the last line. It works in Xcode 7 but not Xcode 8.

It's also worth noting that Xcode 7 has documentation on

but Xcode 8 doesn't.

Type 'CGColorRenderingIntent' has no member 'RenderingIntentDefault'

Code I'm working with:

import CoreImage

// omitted code

public func imageFromPixels(pixels: ([Pixel], width: Int, height: Int)) -> CIImage {
let bitsPerComponent = 8
let bitsPerPixel = 32
let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue) // alpha is last
let providerRef = CGDataProvider(data: NSData(bytes: pixels.0, length: pixels.0.count * sizeof(Pixel)))
let image = CGImageCreate(pixels.1, pixels.2, bitsPerComponent, bitsPerPixel, pixels.1 * sizeof(Pixel), rgbColorSpace, bitmapInfo, providerRef!, nil, true, CGColorRenderingIntent.RenderingIntentDefault)
return CIImage(CGImage: image!)

Apple documentation:

enum CGColorRenderingIntent : Int32 {
case RenderingIntentDefault
case RenderingIntentAbsoluteColorimetric
case RenderingIntentRelativeColorimetric
case RenderingIntentPerceptual
case RenderingIntentSaturation


⌘-click on the symbol CGColorRenderingIntent and you will see

public enum CGColorRenderingIntent : Int32 {

  case defaultIntent
  case absoluteColorimetric
  case relativeColorimetric
  case perceptual
  case saturation 

So it's

let image = CGImage(width: pixels.1, 
                   height: pixels.2, 
         bitsPerComponent: bitsPerComponent, 
             bitsPerPixel: bitsPerPixel, 
              bytesPerRow: pixels.1 * sizeof(Pixel), 
                    space: rgbColorSpace, 
               bitmapInfo: bitmapInfo, 
                 provider: providerRef!, 
                   decode: nil, 
        shouldInterpolate: true, 
                   intent: .defaultIntent)

even the initializer of CGImage has been changed.