<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I would suggest that the way to do it is to follow the NSString/NSNumber approach used in swift-corelibs-foundation where the structural size is equivalent.</div><div class=""><br class=""></div><div class="">the layout would roughly look like:</div><div class=""><br class=""></div><div class=""><div class=""><br class=""></div><div class="">open class InputStream : Stream {</div><div class="">&nbsp; &nbsp; typealias CFType = CFReadStream</div><div class="">&nbsp; &nbsp; // This layout MUST be the same as CFReadStream so that they are bridgeable</div><div class="">&nbsp; &nbsp; private var _base = _CFInfo(typeID: CFReadStreamGetTypeID())</div><div class="">&nbsp; &nbsp; private var _flags: CFOptionFlags = 0</div><div class="">&nbsp; &nbsp; private var _error: UnsafeMutableRawPointer? = nil</div><div class="">&nbsp; &nbsp; private var _info: UnsafeMutableRawPointer? = nil</div><div class="">&nbsp; &nbsp; private var _callBacks: UnsafeMutableRawPointer? = nil</div><div class="">#if os(OSX) || os(iOS)</div><div class="">&nbsp; &nbsp; private var _lock = pthread_mutex_t()</div><div class="">#elseif os(Linux)</div><div class="">&nbsp; &nbsp; private var _lock = Int32(0)</div><div class="">#endif</div><div class="">&nbsp; &nbsp; private var _previousRunloopsAndModes: UnsafeMutableRawPointer? = nil</div><div class="">#if DEPLOYMENT_ENABLE_LIBDISPATCH</div><div class="">&nbsp; &nbsp; private var _queue: UnsafeMutableRawPointer? = nil</div><div class="">#endif</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; internal var _cfObject: CFType {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; return unsafeBitCast(self, to: CFType.self)</div><div class="">&nbsp; &nbsp; }</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; ...</div><div class="">}</div></div><div class=""><br class=""></div><div class="">This would ensure the memory size of the allocation of InputStream would be the same as CFReadStream.&nbsp;</div><div class=""><br class=""></div><div class="">These two calls would then need to be un-commented in NSSwiftRuntime.swift</div><div class=""><br class=""></div><div class="">//&nbsp; &nbsp;&nbsp;_CFRuntimeBridgeTypeToClass(CFReadStreamGetTypeID(), unsafeBitCast(InputStream.self, UnsafeRawPointer.self))<br class="">//&nbsp; &nbsp;&nbsp;_CFRuntimeBridgeTypeToClass(CFWriteStreamGetTypeID(), unsafeBitCast(OutputStream.self, UnsafeRawPointer.self))</div><div class=""><br class=""></div><div class="">and&nbsp;__CFSwiftBridge would need entries for calling out to swift for subclassers.</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 21, 2016, at 1:03 PM, Bouke Haarsma via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">The one that comes with SwiftFoundation (<a href="https://github.com/apple/swift-corelibs-foundation/tree/master/CoreFoundation" class="">https://github.com/apple/swift-corelibs-foundation/tree/master/CoreFoundation</a>).</div><div class=""><br class=""></div><div class="">I think it should be a bug that CFReadStream cannot be bridged to (NS)InputStream, as otherwise there’s no way to intertwine Sockets (CFSockets) with SwiftFoundation. As the implementation already uses a CFReadStream internally (<a href="https://github.com/apple/swift-corelibs-foundation/blob/d3872cb094124d5dd189839505ae73e2fa717cfd/Foundation/NSStream.swift#L122" class="">https://github.com/apple/swift-corelibs-foundation/blob/d3872cb094124d5dd189839505ae73e2fa717cfd/Foundation/NSStream.swift#L122</a>), it would be a matter of adding an initializer. However the value is private, so adding the initializer cannot be done from an extension.</div><div class=""><br class=""></div><div class="">—</div><div class="">Bouke</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 21 Sep 2016, at 21:22, Jens Alfke &lt;<a href="mailto:jens@mooseyard.com" class="">jens@mooseyard.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Sep 20, 2016, at 9:38 PM, Bouke Haarsma via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">When working with CoreFoundation objects (e.g. CFReadStream, CFWriteStream) it isn't immediately obvious to me how to bridge them to SwiftFoundation counterparts (InputStream / OutputStream).</span><br style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">The following works on OSX, but doesn't work on Linux;</span><br style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote></div><br class=""><div class="">What implementation of CF are you using on Linux? OpenStep?</div><div class=""><br class=""></div><div class="">The bridging between Swift and Obj-C Foundation classes is only implemented on Apple platforms. It’s not part of the open source release. The plan is to implement classes like InputStream in native Swift as part of the standard library; that work is in progress.</div><div class=""><br class=""></div><div class="">—Jens</div></div></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>