How to Fix Error CGContextSetStrokeColorWithColor: invalid context 0x0

CGContextSetStrokeColorWithColor: invalid context 0x0.
1. Error name: CGContextSaveGState: invalid context 0x0. CGContextDrawPath: invalid context 0x0. And so on. I compiled with no errors or warnings until runtime when I printed a series of &lt’s on the console. Error> The information is shown below (error message)

The error message

The reason for this error is not doing something improper to layer in the view’s -drawrect: method such as UIBezierPath’s – (void)setFill; – (void)setStroke; Method UIColor – (void)setFill; – (void)setStroke; Methods, etc.
2. Solutions
(1). Encapsulate the operations on the View Layer layer separately into the -drawRect: method of a View class
(2). Do not call the related method, the official annotation is generally given, com+ click to view: Drawing the context)

Officially given limits -& GT; drawing context

 

Read More: