问题
What would be the equivalent in swift of this Obj-C code?
I'm guessing something with CMutableVoidPointer
static void *CapturingStillImageContext = &CapturingStillImageContext;
回答1:
Probably something like this:
var CapturingStillImageContext: COpaquePointer = nil
withUnsafePointer(&CapturingStillImageContext) {
CapturingStillImageContext = COpaquePointer($0) }
回答2:
CMutableVoidPointer
isn't available anymore as of Beta 3. Theres UnsafePointer
and ConstUnsafePointer
- you can declare it this way:
let CapturingStillImageContext = UnsafePointer<()>()
回答3:
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) } )
}
来源:https://stackoverflow.com/questions/24628304/declaring-self-referencing-pointers-in-swift