[swift-dev] Unmanaged API flip flop

Kyle Jessup kjessup.lists at gmail.com
Mon Jul 4 15:32:35 CDT 2016


I have this code which uses Unmanaged and the API seems to vary depending on if I am using a 3.0 Preview or a development snapshot. I see it now when trying the June 13th/27th preview vs June 20th snapshot.

class MyClass {}

let holderObject = MyClass()

#if FLIP // works with PREVIEW
	let leakyObject = UnsafeMutablePointer<Void>(OpaquePointer(bitPattern: Unmanaged.passRetained(holderObject)))
#else // works with SNAPSHOT
	let leakyObject = Unmanaged.passRetained(holderObject).toOpaque()
#endif

#if FLIP // works with PREVIEW
	let unleakyObject = Unmanaged<MyClass>.fromOpaque(OpaquePointer(leakyObject)).takeRetainedValue()
#else // works with SNAPSHOT
	let unleakyObject = Unmanaged<MyClass>.fromOpaque(leakyObject).takeRetainedValue()
#endif

I see the same difference between the previous snapshots and previews all the way back to the “false” preview of yore.

Am I misunderstanding something about the API or is this a bug?

Thanks,
-Kyle


More information about the swift-dev mailing list