title: Drawing lines in Swift
body: <p>I'm drawing a horizontal line and a vertical line on a <code>UITableViewCell</code> using the following code and it works fine on iOS7. Its in Objective-C.</p>
  
  <p>In the subclass of the,</p>
  
  <pre><code>@property (strong, nonatomic) NSMutableArray *columns;
  
  - (void)drawRect:(CGRect)rect
  {
      // In iOS7, you have to set the cell's background color to clear otherwise the drawing lines won't appear
      self.backgroundColor = [UIColor clearColor];
  
      // Drawing the vertical line
      CGContextRef ctx = UIGraphicsGetCurrentContext();
      CGContextSetRGBStrokeColor(ctx, 0.5, 0.5, 0.5, 1.0);
      CGContextSetLineWidth(ctx, 0.75);
      for (int i = 0; i &lt; self.columns.count; i++) {
          CGFloat f = [((NSNumber*) [self.columns objectAtIndex:i]) floatValue];
          CGContextMoveToPoint(ctx, f, 10);
          CGContextAddLineToPoint(ctx, f, self.bounds.size.height - 10);
      }
      CGContextStrokePath(ctx);
  
      // Drawing the horizontal line
      CGContextRef cntx = UIGraphicsGetCurrentContext();
      CGContextSetRGBStrokeColor(ctx, 0.5, 0.5, 0.5, 1.0);
      CGContextSetLineWidth(cntx, 1);
      for (int i = 0; i &lt; self.columns.count; i++) {
          CGContextMoveToPoint(cntx, 15, self.bounds.size.height / 2);
          CGContextAddLineToPoint(cntx, 60, self.bounds.size.height / 2);
      }
      CGContextStrokePath(cntx);
  
      [super drawRect:rect];
  }
  
  - (void)addColumn:(CGFloat)position
  {
      [self.columns addObject:[NSNumber numberWithFloat:position]];
  }
  </code></pre>
  
  <p>And it looks like this,</p>
  
  <p><img src="https://i.stack.imgur.com/qdQPK.png" alt="enter image description here"></p>
  
  <p>I'm trying to implement the same in Swift. However those lines don't appear. Here is my code so far,</p>
  
  <pre><code>var columns: [CGFloat] = []
  
  override func drawRect(rect: CGRect)  {
  
      // Drawing the vertical line
      let ctx = UIGraphicsGetCurrentContext()
      CGContextSetRGBStrokeColor(ctx, 0.5, 0.5, 0.5, 1.0)
      CGContextSetLineWidth(ctx, 0.75)
      for var i = 0; i &lt; self.columns.count; i++ {
          let f = self.columns[i] as? float // Error - Use of module 'float' as a type
          CGContextMoveToPoint(ctx, f, 10)
          CGContextAddLineToPoint(ctx, f, self.bounds.size.height - 10)
      }
      CGContextStrokePath(ctx)
  
      // Drawing the horizontal line
      let cntx = UIGraphicsGetCurrentContext()
      CGContextSetRGBStrokeColor(ctx, 0.5, 0.5, 0.5, 1.0)
      CGContextSetLineWidth(cntx, 1)
      for var i = 0; i &lt; self.columns.count; i++ {
          CGContextMoveToPoint(cntx, 15, self.bounds.size.height / 2)
          CGContextAddLineToPoint(cntx, 60, self.bounds.size.height / 2)
      }
      CGContextStrokePath(cntx)
  
      self.backgroundColor = UIColor.clearColor()
  
      super.drawRect(rect)
  }
  
  func addColumn(position: CGFloat) {
      self.columns.append(NSNumber.numberWithFloat(position)) // Error - 'NSNumber' is not a subtype of 'Float'
  }
  </code></pre>
  
  <p>Multiple errors come up in the first block of the code. The error message is <strong>'AnyObject' is not convertible to 'CGFloat'</strong>.
  No errors in the second block but still the line doesn't appear.</p>
  
  <p>Can someone please tell me what I'm missing here?</p>
  
  <p>Thank you.</p>