UnsafePointer <CGAffineTransform> of CGAffineTransform
I am trying to create CGPath in Swift. I am using CGPathCreateWithRect(rect, transformPointer) .
How can I get UnsafePointer<CGAffineTransform> from CGAffineTransform ? I tried this:
let transform : CGAffineTransform = CGAffineTransformIdentity let transformPointer : UnsafePointer<CGAffineTransform> = UnsafePointer(transform) I also tried this:
let transform : CGAffineTransform = CGAffineTransformIdentity let transformPointer : UnsafePointer<CGAffineTransform> = &transform but Swift complains about '&' with non-inout argument of type... I also tried passing &transform directly to CGPathCreateWithRect , but this stops with the same error.
When I pass transform directly, Swift "Cannot convert a value of type" CGAffineTransform "to the expected argument type" UnsafePointer ".
What happens and how to do it with Swift 2.1?
You were almost there.I also tried passing & converting directly to CGPathCreateWithRect ...
transform must be a variable to pass it as an inout argument with & : var transform = CGAffineTransformIdentity let path = CGPathCreateWithRect(CGRect(...), &transform) For more information, see “Interacting with the API API” in the “Using Swift with Cocoa and Objective-C” section.
In Swift 3, it will be
var transform = CGAffineTransform.identity let path = CGPath(rect: rect, transform: &transform) or, to transform identity, simply
let path = CGPath(rect: rect, transform: nil)