Why do CGContextSetFillColorWithColor and CGContextFillRects both throw "invalid context 0x0" error?
<p>This code:</p>

<pre><code>    let rect = CGRectMake( 0.0, 0.0, 16.0, 16.0 )
    let context = UIGraphicsGetCurrentContext()

    UIGraphicsBeginImageContext( rect.size )
    CGContextSetFillColorWithColor( context, color.CGColor )
    CGContextFillRect( context, rect )

    let image = UIGraphicsGetImageFromCurrentImageContext()

    UIGraphicsEndImageContext()
</code></pre>

<p>Is throwing these errors:</p>

<pre><code>MakeImage[60890] &lt;Error&gt;: CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
MakeImage[60890] &lt;Error&gt;: CGContextFillRects: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
</code></pre>

<p>CGRect size seems fine, which <a href="https://stackoverflow.com/questions/19940543/cgcontextsetfillcolorwithcolor-invalid-context-0x0">other posts</a> suggest as the problem. So what else is incorrectly set, please? Thank you. </p>