title: Display NSImage on a CALayer
body: <p>I've been trying to display a NSImage on a CALayer. Then I realised I need to convert it to a CGImage apparently, then display it...</p>
  
  <p>I have this code which doesn't seem to be working</p>
  
  <pre><code>CALayer *layer = [CALayer layer];
  
      NSImage *finderIcon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kFinderIcon)];
      [finderIcon setSize:(NSSize){ 128.0f, 128.0f }];
  
      CGImageSourceRef source;
      source = CGImageSourceCreateWithData((CFDataRef)finderIcon, NULL);
      CGImageRef finalIcon =  CGImageSourceCreateImageAtIndex(source, 0, NULL);
  
      layer.bounds = CGRectMake(128.0f, 128.0f, 4, 4);
      layer.position = CGPointMake(128.0f, 128.0f);
      layer.contents = finalIcon;
  
          // Insert the layer into the root layer
      [mainLayer addSublayer:layer];
  </code></pre>
  
  <p>Why? How can I get this to work?</p>