<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">So there are a couple of ways objects can be bridged:</div><div class=""><br class=""></div><div class="">1) has-a style bridges - RunLoop and CFRunLoop for example. The only association is where RunLoop contains a CFRunLoop and there is a method to fetch the CFRunLoop out of the RunLoop. Some times this relationship is not public.</div><div class=""><br class=""></div><div class="">2) is-a style bridges - NSCFString and CFString for example. These are where the structural size and layout of the objects are identical. So when casting the only change is a re-interpretation of the type and the underlying data structure backing the object is exactly the same.</div><div class=""><br class=""></div><div class="">3) toll-free bridges - NSString and CFString for example. CF can take NSStrings because the methods that transact upon CFStrings all check to determine if the object being passed is a subclass of NSString or if it is a NSCFString, in the NSString subclass cases it will dispatch calls out to the subclass to specific funnel points such that it can reasonably transact upon that object.</div><div class=""><br class=""></div><div class="">4) Compiler generated struct to reference bridges - NSString and String. When the translation occurs the compiler emits a call to a method on String to convert NSString to String. This is just a specialized and automatically generated form of style 1</div><div class=""><br class=""></div><div class="">The styles 1, 2 and 3 work for swift-corelibs-foundation, however 4 is disabled for linux even though we have both the reference types and the structural types.&nbsp;</div><div class=""><br class=""></div><div class="">On Darwin CFReadStream is actually a NSCFInputStream (which is a subclass of NSInputStream) but currently in swift-corelibs-foundation CFReadStream is a NSCFType (I would consider that discrepancy an incomplete point of swift-corelibs-foundation) with an ivar of a CFReadStream. So what would need to be done is that InputStream and OutputStream would need to be made conditionally abstract and the ivar layout would need to exactly mimic the layout of the CF counterpart. Two new subclasses would need to be made to dispatch back into CF the functionality for streams created from CF and dispatching methods would need to be made. Doing this would make InputStream and OutputStream more like NSString (which might be a decent place to take a look at how it works).</div><div class=""><br class=""></div><div class="">Let me know if there is anything I can help clear up on more.</div><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 20, 2016, at 11:29 PM, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><br class=""><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(127, 127, 127, 1.0);" class=""><b class="">From: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Bouke Haarsma via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt;<br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(127, 127, 127, 1.0);" class=""><b class="">Subject: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class=""><b class="">How to bridge between CoreFoundation and SwiftFoundation on Linux?</b><br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(127, 127, 127, 1.0);" class=""><b class="">Date: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">September 20, 2016 at 9:38:54 PM PDT<br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(127, 127, 127, 1.0);" class=""><b class="">To: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(127, 127, 127, 1.0);" class=""><b class="">Reply-To: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Bouke Haarsma &lt;<a href="mailto:bouke@haarsma.eu" class="">bouke@haarsma.eu</a>&gt;<br class=""></span></div><br class=""><br class="">Hi all,<br class=""><br class="">When working with CoreFoundation objects (e.g. CFReadStream, <br class="">CFWriteStream) it isn't immediately obvious to me how to bridge them to <br class="">SwiftFoundation counterparts (InputStream / OutputStream).<br class=""><br class="">The following works on OSX, but doesn't work on Linux;<br class=""><br class=""> &nbsp;&nbsp;&nbsp;let readStream: CFReadStream = ...<br class=""> &nbsp;&nbsp;&nbsp;readStream as InputStream<br class=""> &nbsp;&nbsp;&nbsp;// error: cannot convert value of type 'CFReadStream' to expected <br class="">argument type 'InputStream'<br class=""><br class="">In some other places I need to bridge a String to a CFString, the <br class="">following works on OSX, but doesn't work on Linux;<br class=""><br class=""> &nbsp;&nbsp;&nbsp;let string: String = ...<br class=""> &nbsp;&nbsp;&nbsp;string as CFString<br class=""> &nbsp;&nbsp;&nbsp;// error: error: 'String' is not convertible to 'CFString'; did you <br class="">mean to use 'as!' to force downcast?<br class=""><br class="">Thanks.<br class=""><br class="">-- <br class="">-Bouke<br class=""><br class=""><br class="">_______________________________________________<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=""><br class=""><br class=""><br class=""><br class="">-- <br class="">-Dave<br class=""></div></blockquote></div><br class=""></body></html>