Tag Archives: Summary of iOS development errors

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

 

Error: cocoa error 3840

false

when using AFNetworking POST to connect to WEB API, error:
“The operation couldn’t e completed. (Cocoa error 3840).”

Error Domain=NSCocoaErrorDomain Code=3840 “The operation couldn’t be completed. (Cocoa Error 3840.)” (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x1667f670 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

solution

this is a JSON parsing error, which in general is probably caused by the incorrect format of the JSON data returned by your WEB API.

therefore, make sure that the return value of the WEB API is in the correct and valid JSON format. You can check with the following online JSON validation tool.

recommendation article: network requests and various error Code summary (Errors Code)