title: Where is the CGColorSpace for RGBA?
body: <p>I am trying to draw a circle shaded with a gradient from white to transparent. I am using Core Graphics.</p>
  
  <p>Here is what I have which draws a gradient from white to black:</p>
  
  <pre><code>let colorSpace = CGColorSpaceCreateDeviceRGB();
  let colors = [UIColor.white.cgColor, UIColor.black.cgColor] as CFArray;
  let locations : [CGFloat] = [0.0, 1.0];
  let glowGradient : CGGradient = CGGradient.init(colorsSpace: colorSpace, colors: colors, locations: locations)!;
  let ctx = UIGraphicsGetCurrentContext()!;
  ctx.drawRadialGradient(glowGradient, startCenter: rectCenter, startRadius: 0, endCenter: rectCenter, endRadius: imageWidthPts/2, options: []);
  </code></pre>
  
  <p>However, I do not want to draw white-to-black; I want to draw white-to-transparent.</p>
  
  <p>To do so, I first tried changing the end color to <code>UIColor.white.cgColor.copy(alpha: 0.0)</code> (i.e., transparent white). However, this failed with:</p>
  
  <pre><code>fatal error: unexpectedly found nil while unwrapping an Optional value
  </code></pre>
  
  <p>I assume this error is due to the color being outside the specified RGB color space (<code>CGColorSpaceCreateDeviceRGB()</code>).</p>
  
  <p>The fix would seem to be to change the specified color space to one with an alpha component, such as RGBA. However, such color spaces do not appear to exist! There are only <code>CGColorSpaceCreateDeviceRGB</code>, <code>CGColorSpaceCreateDeviceCMYK</code>, and <code>CGColorSpaceCreateDeviceGray</code>.</p>
  
  <p>But it makes no sense for there to be no available color spaces with an alpha component. The documentation explicitly describes support for alpha in gradients. <a href="https://developer.apple.com/reference/coregraphics/cggradient/1398454-init" rel="nofollow">The documentation for <code>CGGradient.init</code></a> says:</p>
  
  <blockquote>
    <p>For example, if the color space is an RGBA color space and you want to use two colors in the gradient (one for a starting location and another for an ending location), then you need to provide 8 values in <code>components</code>—red, green, blue, and alpha values for the first color, followed by red, green, blue, and alpha values for the second color.</p>
  </blockquote>
  
  <p>This RGBA encoding makes perfect sense, but it's impossible to tell Core Graphics that I'm using such an RGBA encoding, because there is no RGBA color space!</p>
  
  <p>Where is the <code>CGColorSpace</code> for RGBA?</p>