I'm trying to create a CGContext in which I can draw an image to retrieve the raw pixel data for later processing. I'm creating the CGContext using a color space dependent upon the image I'm processing. This works fine when I use a grayscale or CMYK colorspace, but I can't get a valid CGContext when working with any RGB color space. The snippets below illustrate the behavior I'm seeing (with Swift 4, XCode 10.1). I've got to be missing something obvious but for the life of me I can't find it. Any help would be greatly appreciated!
//let colorSpace3:CGColorSpace = CGColorSpaceCreateDeviceGray() // get good context
//let colorSpace3:CGColorSpace = CGColorSpaceCreateDeviceCMYK() // get good context
//let colorSpace3: CGColorSpace = CGColorSpace(name: CGColorSpace.linearGray)! // get good context
//let colorSpace3: CGColorSpace = CGColorSpace(name: CGColorSpace.genericCMYK)! // get good context
//let colorSpace3:CGColorSpace = CGColorSpaceCreateDeviceRGB() //context3 is nil
//let colorSpace3: CGColorSpace = CGColorSpace(name: CGColorSpace.sRGB)! //context3 is nil
//let colorSpace3: CGColorSpace = CGColorSpace(name: CGColorSpace.linearSRGB)! // context3 is nil
let colorSpace3: CGColorSpace = CGColorSpace(name: CGColorSpace.adobeRGB1998)! // context3 is nil
let bmpinfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue) // bmpinfo different settings doesn't change behavior
let context3 = CGContext(data: nil, width: 256, height: 256, bitsPerComponent: 8, bytesPerRow: 0, space: colorSpace3, bitmapInfo: bmpinfo.rawValue)
print(context3) // prints nil whenever colorSpace3 is an RGB space??