Why Is 'Nil' Not Compatible With 'Unsafepointer≪Cgaffinetransform≫' in Swift 3

Why is 'nil' not compatible with 'UnsafePointerCGAffineTransform' in Swift 3?

Try this:

let path = CGMutablePath()
path.move(to: CGPoint(x: 30, y: 0))

CGPath APIs are now imported as instance methods in Swift 3.
You can check them with Command-clicking on CGMutablePath.
Or see the latest reference of CGMutablePath.

CGPath not working in Swift 3

Most of the syntaxes are changed in Swift 3, But they didn't removed any API methods(like CGPathMoveToPoint) and It's just renamed like below.

let path = CGMutablePath()
path.move(to: CGPoint(x: 10.0, y: 10.0))
path.addLine(to: CGPoint(x: 10.0, y: 10.0))

UnsafePointerCGAffineTransform from CGAffineTransform

@Martin R provides the best answer, but as an alternative, I like to use my unsafe mutable pointers this way, in case you need to alter the actual pointer in the future

let path = withUnsafeMutablePointer(&transform)
{
CGPathCreateWithRect(CGRect(...), UnsafeMutablePointer($0))
}


Related Topics



Leave a reply



Submit