title: How to add a CALayer to an NSView on Mac OS X
body: <p>I'm trying to learn how to use and implement <code>CALayer</code> in a Mac Objective-C application, but I can't seem to probably do the most basic thing - add a new layer and set its background colour/frame size. Can anyone see what is wrong with my code?</p>
  
  <pre><code>CALayer *layer = [CALayer layer];
  [layer setFrame:CGRectMake(0, 0, 100, 100)];
  [layer setBackgroundColor:CGColorCreateGenericRGB(1.0, 0.0, 0.0, 1.0)];
  [self.layer addSublayer:layer];
  [layer display];
  </code></pre>
  
  <p>I put this in the <code>- (void)drawRect:(NSRect)rect</code> method of my custom <code>NSView</code> subclass, but when I run the application, it just shows a blank view, with no background colour or evidence of the layer I created. </p>