I am trying to create a CGContext in swift. It compiles but throws an error at runtime.
let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()
let conte
Suggested way compatible with both Xcode 8.3 and Xcode 9 which supports Swift 3 and Swift 4
let colorSpace = CGColorSpaceCreateDeviceRGB()
guard let bitmapContext = CGContext(data: nil,
width: Int(size.width),
height: Int(size.height),
bitsPerComponent: Int(bitsPerComponent),
bytesPerRow: Int(bytesPerRow),
space: colorSpace,
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else {
return nil
}