このコードは、ビュー内の赤い四角形を塗りつぶします。
let context:CGContextRef = NSGraphicsContext.currentContext()!.CGContext
var pathPoint:CGPoint = CGPoint()
pathPoint.x = CGFloat(225.0)
pathPoint.y = CGFloat(100.0)
var myMutablePath:CGMutablePath = CGPathCreateMutable()
CGPathMoveToPoint(myMutablePath, nil, pathPoint.x, pathPoint.y)
CGPathAddLineToPoint(myMutablePath, nil, pathPoint.x + CGFloat(50.0), pathPoint.y)
CGPathAddLineToPoint(myMutablePath, nil, pathPoint.x + CGFloat(50.0), pathPoint.y + CGFloat(50.0))
CGPathAddLineToPoint(myMutablePath, nil, pathPoint.x, pathPoint.y + CGFloat(50.0))
CGPathAddLineToPoint(myMutablePath, nil, pathPoint.x, pathPoint.y)
CGContextAddPath(context, myMutablePath);
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0)
CGContextFillPath(context)