Thomas Denney

CGContextRef in Swift

A lot of code that I’ve seen on StackOverflow for correctly getting the CGContextRef from an NSGraphicsContext in Swift doesn’t seem to be working in OSX 10.9. The following does work as of Xcode 6 beta 4 running on OSX 10.9:

var context:CGContextRef = reinterpretCast(NSGraphicsContext.currentContext().graphicsPort)

In OSX 10.10 a new method is available on NSGraphicsContext that returns the CGContextRef however I haven’t had this correctly working with Quartz.