Unsafe pointers in Swift: Conversion to and from a COpaquePointer (and CFunctionPointer) (Part II, Xcode 6 Beta 6; update Swift 3, Xcode 8)
The unsafe pointers in Swift posts, of which this is the second, are a tentative toe-dipping into the world of connecting Swift with the C functions provided in Apple's Darwin -> C -> stdlib header file. As such, this post is neither exhaustive nor expert, I am simply trying to fill a void where I find little else to work with in my experimentations. You should read the code found here as if it were written in someone's personal notebook and never use it without first understanding it and satisfying yourself that it works correctly. COpaquePointer With all of this in mind, here is my code for today, fulfilling the conversion of an UnsafeMutablePointer to and from a COpaquePointer: let str = "Hello, pointer" let ps = UnsafeMutablePointer<String>.alloc(1) // allocate memory for one String instance ps.initialize(str) // intialize with a value let cps = COpaquePointer(ps) // convert UnsafeMutablePointer to COpaquePointer let nps = UnsafeMutablePointer&l