Value of type 'UIGraphicsPDFRenderer' has no member 'pdfData'

I'm trying to create PDF files using UIGraphicsRenderer.

While trying out the code from this tutorial, I encountered the above error when trying to call the pdfData method. The code(almost identical to the one in the tutorial) is reproduced below, with the error found at line 12. Is the .pdfData method somehow missing, or am I doing something wrong?

Code Block
class UIGraphicsPDFRenderer : UIGraphicsRenderer {
}
var rendererformat = UIGraphicsPDFRendererFormat()
var renderer = UIGraphicsPDFRenderer()
"""Drawing the PDF"""
let pdf = renderer.pdfData() { (context) in
  context.beginPage()
  let attributes = [
    NSFontAttributeName : UIFont.boldSystemFont(ofSize: 150)
  ]
  let text = "Hello!" as NSString
  text.draw(in: CGRect(x: 0, y: 0, width: 500, height: 200), withAttributes: attributes)
}



Replies

or am I doing something wrong? 

YES.
The link you have shown is not a tutorial. It is a documentation of a class and not intended for a tutorial.
Especially, this line:
Code Block
class UIGraphicsPDFRenderer : UIGraphicsRenderer

It shows that UIGraphicsPDFRenderer is a class and it is a subclass of UIGraphicsRenderer.
The line is not showing anything which needs to be included in your code.

Remove these lines:
Code Block
class UIGraphicsPDFRenderer : UIGraphicsRenderer {
}



Any other codes and descriptions are not intended to be a tutorial, but just an outlined guide to use the class.
You may need to fill in many missing parts, and fix some other parts depending on your environment and context.
Here is a real tutorial.

https ://www.raywenderlich .com/4023941-creating-a-pdf-in-swift-with-pdfkit