<div dir="ltr">One hopes to avoid COpaquePointer and Unsafe(Mutable)Pointer, but in practice I've had occasion to use them a few times.<div><br></div><div>Things that are nice:</div><div><br></div><div>- Unmanaged.passUnretained/takeRetained/etc. which make memory management semantics explicit.</div><div><div><br></div><div>Things I've been frustrated by:</div><div><br></div><div>- An API takes UnsafeMutablePointer<Void>, but Unmanaged.toOpaque() returns a COpaquePointer.</div><div><br></div><div>- An API gives me UnsafeMutablePointer<Void>, but Unmanaged.fromOpaque() takes a COpaquePointer.</div><div><br></div><div><br></div><div>In practice, I end up with monstrosities like:</div><div><br></div><div><span style="font-family:monospace,monospace">Unmanaged.passRetained(CFCopyDescription(Unmanaged<AnyObject>.fromOpaque(COpaquePointer($0)).takeUnretainedValue()))</span></div><div><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><br></div><div>I think a few things could help:</div><div><br></div><div>- Phase out COpaquePointer in favor of UnsafePointer<Void> (is this already happening?)</div><div><br></div><div>- Add implicit conversion from COpaquePointer to Unsafe(Mutable)Pointer<Void>, and/or vice versa.</div><div><br></div><div>- Even better, add implicit conversion from Unmanaged<T> to COpaquePointer or UnsafePointer<Void>, behaving the way toOpaque() currently does. Also, replace Unmanaged.fromOpaque() with an initializer Unmanaged(_: UnsafePointer<Void>).</div><div><br></div><div><br></div><div>What are others' experiences? Would it be feasible/favorable to have some of these conversions?</div><div><br></div><div>Jacob Bandes-Storch<br></div></div></div></div>
</div></div></div>