4

What would be the equivalent in swift of this Obj-C code?

I'm guessing something with CMutableVoidPointer

static void *CapturingStillImageContext = &CapturingStillImageContext;

3 Answers3

3

CMutableVoidPointer isn't available anymore as of Beta 3. Theres UnsafePointer and ConstUnsafePointer - you can declare it this way:

let CapturingStillImageContext = UnsafePointer<()>()
artey
  • 1,243
  • 7
  • 10
1

Probably something like this:

var CapturingStillImageContext: COpaquePointer = nil
withUnsafePointer(&CapturingStillImageContext) {
    CapturingStillImageContext = COpaquePointer($0) }
newacct
  • 119,665
  • 29
  • 163
  • 224
0

I've been using this technique, but it would be nice to find a more elegant solution:

var SelfReferencingKey = initialize_SelfReferencingKey()

func initialize_SelfReferencingKey() -> UnsafePointer<()> {
    return withUnsafePointer(&SelfReferencingKey, { UnsafePointer($0) } )
}
Eric
  • 139
  • 1
  • 4