Thanks Braden for pointing out that toOpaque() was just a cast of c to
UnsafeMutableRawPointer. And thanks Guillaume too, I now understand why
my code doesn't and can't work.
All this messing around has confused me greatly and I lost track of
what I originally wanted to do :).
At first, I wanted
[re-sending to the list, and elaborating]
You are making the runtime use the first word of the referent as if it were the
reference.
The lowercase-c variable is a reference. rawPointer contains the same value,
and points to the beginning of the object data. Your typecasting is telling the
After doing some testing I looked up the implementation and Unmanaged it is
very misleading in how it is behaves and is implemented.
When you call toOpaque() it returns the result of unsafeBitCast(_value, to:
UnsafeRawPointer.self). _value is an internal field we can't directly
access, in your
> On Sep 23, 2017, at 3:44 AM, nyg nyg via swift-users
> wrote:
>
> Hello all,
>
> I'm trying to get an UnsafeMutablePointer from an
> UnsafeMutableRawPointer obtained using the Unmanaged structure:
>
> class C { var foo = 42, bar = "bar" }
> let c = C()
>
> let
Hello all,
I'm trying to get an UnsafeMutablePointer from an
UnsafeMutableRawPointer obtained using the Unmanaged structure:
class C { var foo = 42, bar = "bar" }
let c = C()
let rawPointer = Unmanaged.passUnretained(c).toOpaque()
let pointer = rawPointer.bindMemory(to: C.self, capacity: 1)