I'm wondering how to convert the following objective-c method to Swift function?
CGPatternRef pattern = CGPatternCreate(NULL,
rect,
CGAffineTransformIdentity,
24,
24,
kCGPatternTilingConstantSpacing,
true,
&callbacks);
My code:
let callbacks : CGPatternCallbacks = CGPatternCallbacks(version: 0)
let pattern : CGPatternRef = CGPatternCreate(nil,
rect,
CGAffineTransformIdentity,
24,
24,
kCGPatternTilingConstantSpacing,
true,
callbacks)
But I got an error message:
'CGPatternCallbacks' is not convertible to 'CConstPointer'
Is there any sample code for this? Thanks
Something like that
var callbacks : CGPatternCallbacks = CGPatternCallbacks(version: 0)
var pattern = CGPatternCreate(nil,
rect,
CGAffineTransformIdentity,
24,
24,
kCGPatternTilingConstantSpacing,
true,
&callbacks)
This solution is a problematic one:
The pointer registered within CGPatternCallbacks (for a function that draws the pattern) should be CFunctionPointer<(UnsafeMutablePointer, CGContext>)->Void) This means that the function pointer should be transformed to UnasfeMutablePointer then to COpaquePointer then to CFuncfionPointer
And still anyway i'm getting an exception on function call, there is a simplier solution: [http://www.raywenderlich.com/90695/modern-core-graphics-with-swift-part-3][1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With