<div dir="ltr"><p style="margin:0px;line-height:normal;font-family:Helvetica">Having reference semantics counterpart of value types in an easier way</p>
<p style="margin:0px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">Introduction</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">———————</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">Now swift has its basic datatypes as value semantics. Arrays, Int. Dictionaries, Sets and … are struct types without any kind of inheritance.</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">To compensate it, programmers usually use NS classes of these types. We are about to introducing a new way to have reference types in a more swifty way rather than using Foundation framework.</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">Swift 3 introduce omitting NS prefix from Foundation framework but leaves NS prefix for some types with struct counterparts like Array, which may leads to inconstancy for developers, and many datatypes remain classes (e.g URL) which should be struct in swift paradigm while they remained classes</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">Motivation</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">———————</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">Programmers usually have to memorize the counterpart of Swift datatypes in Foundation easily.  Besides many datatypes remain classes (e.g URL) which should be struct in swift paradigm while they remained classes</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">Proposed solution</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">———————</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">We can match existing classes to their value-type counterpart like this:</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">class Array: NSArray as reftype of Array {</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">}</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">The compiler should check all Array struct functions are implemented in this new class type otherwise throw an compile error. For de novo declarations:</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">class ValType as reftype of ValType {</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">}</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">here, the only thing user has to is reimplement mutating functions here, or use Bridgeable protocol. I&#39;ve no idea here yet</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">To create a reference Array (former NSArray) programmer can simply do:</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">let NSArrayInstance: *Array[NSObject] = [];</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">or</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">let NSArrayInstance: reftype Array[NSObject] = [];</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">Alternative solution</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">———————</span></p>
<p style="margin:0px;line-height:normal;font-family:Helvetica"><span style="">Leave Foundation framework as it is by now.</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Helvetica;min-height:13px"><span style=""></span><br></p></div>