title: Create a custom CALayer implementation
body: <p>I'm trying to learn Core Animation to develop a certain app but I need to subclass the CALayer class, however I'm struggling to get the layer to draw itself.</p>
  
  <p>I need the custom CALayer to have some additional properties and handle custom events (touching and such) but from the start the basic CALayer I'm implementing is not drawing itself, can anyone tell me what I'm doing wrong?</p>
  
  <p>I'm have a 
  MagicSquare</p>
  
  <pre><code>#import "MagicSquare.h"
  
  @implementation MagicSquare
  
  
  -(id) initWithLayer:(id)layer {
      self = [super initWithLayer:layer];
  
  
      self.bounds = CGRectMake(0, 0, 200, 200);
      self.position = CGPointMake(10,10);
      self.cornerRadius = 100;
      self.borderColor = [UIColor redColor].CGColor;
      self.borderWidth = 1.5;
  
      return self;
  }
  
  - (void)drawInContext:(CGContextRef)theContext
  {
  
      NSLog(@"Drawing");
      CGMutablePathRef thePath = CGPathCreateMutable();
  
      CGPathMoveToPoint(thePath,NULL,15.0f,15.f);
      CGPathAddCurveToPoint(thePath,
                            NULL,
                            15.f,250.0f,
                            295.0f,250.0f,
                            295.0f,15.0f);
  
      CGContextBeginPath(theContext);
      CGContextAddPath(theContext, thePath );
  
      CGContextSetLineWidth(theContext,
                            1.0);
      CGContextSetStrokeColorWithColor(theContext,
                                       [UIColor redColor].CGColor);
      CGContextStrokePath(theContext);
      CFRelease(thePath);
  }
  </code></pre>
  
  <p>and here's how I'm trying to have it draw on the main controller</p>
  
  <pre><code>@implementation BIDViewController
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
  
      MagicSquare *layer = [[MagicSquare alloc] initWithLayer:[CALayer layer]];
  
      [self.view.layer addSublayer:layer];
  
  }
  </code></pre>