Search code examples
swiftcgpathref

unable to call CGPathMoveToPoint() with nil in Swift


I have tried to call CGPathMoveToPoint() in Swift using the CGMutablePathRef and a CGPoint as input and NULL/nil instead of the CGAffineTransformation like this

CGPathMoveToPoint(path, nil, point.x as CGFloat, point.y as CGFloat)

However, I always get an error stating the expression cannot be converted to type NilLiteralConvertible. Do you have any idea why this code does not work? What should be used in Swift insted of the nil argument? I tried using CGAffineTransformidentity instead of nil but it doesn't work either. Thanks!


Solution

  • I suspect your path - you have not shown what it is, so how do we know it is really a CGPath? However, there's also this:

    point.x as CGFloat
    

    That is not Swift. You want to say CGFloat(point.x) (and so too for point.y) if it is not a CGFloat already.