iosswiftios10uigraphicsrenderer

How to use `prepare(_ context: CGContext, with rendererContext: UIGraphicsRendererContext)`?


Starting iOS 10, Apple documents this class function in UIKit:

class func prepare(_ context: CGContext, with rendererContext: UIGraphicsRendererContext)

However, I was not able to access prepare in Xcode 8.3.3:

// error: Type 'UIGraphicsRenderer' has no member 'prepare'
UIGraphicsRenderer.prepare(UIGraphicsGetCurrentContext()!, with: UIGraphicsRendererContext())

// error: Type 'UIGraphicsImageRenderer' has no member 'prepare'
UIGraphicsImageRenderer.prepare(UIGraphicsGetCurrentContext()!, with: UIGraphicsRendererContext())

Solution

  • The function prepare is defined in UIGraphicsRendererSubclass You can import this class with callingimport UIKit.UIGraphicsRendererSubclass