1

Im trying to create a CGPattern using callbacks however the following method signature is not of CGPatternDrawPatternCallback type and I can not determine what it should be

func patternDefinitionFunction(#info: UnsafeMutablePointer<Void>, c: CGContext?)
Neil Horton
  • 707
  • 6
  • 13
  • See https://stackoverflow.com/questions/44211720/trouble-using-callbacks-with-cgpattern-in-swift3 for a Swift3 version of using `CGPattern`. – rmaddy May 27 '17 at 02:49

1 Answers1

1

You can't do this in Swift 1.2 or earlier; you'd have to write this part of your code in Objective-C. To write a C function in Swift, you'll need to update to Swift 2.0 (available in the Xcode 7 beta currently).

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • How would you define the function in swift 2.0? – Neil Horton Jul 25 '15 at 16:40
  • It's totally straightforward in Swift 2.0 - it's exactly like writing it in Objective-C, only it's even easier. The CGPatternDrawPatternCallback function must be defined at top level or as a local func; the latter is probably what you'll prefer. Then just use the name of the function as the second argument to the CGPatternCallbacks constructor and pass the address of the resulting CGPatternCallbacks object in as the last argument in your pattern creation call. – matt Jul 25 '15 at 18:40
  • Why it isn't possible in swift 1.2? – kelin Aug 31 '15 at 10:19