<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I just mentioned this in my other email, but to point out here: the reason this works in your case is because you adopt these methods as <font face="SFMono-Regular" class="">static func</font><font face="SFHello-Regular" class="">s and can reasonably rely on subclasses of </font><font face="SFMono-Regular" class="">NSData</font><font face="SFHello-Regular" class="">, </font><font face="SFMono-Regular" class="">NSNumber</font><font face="SFHello-Regular" class="">, </font><font face="SFMono-Regular" class="">NSString</font><font face="SFHello-Regular" class="">, etc. to do the right thing because of work done behind the scenes in the ObjC implementations of these classes (and because we’ve got established subclassing requirements on these methods — all subclasses of these classes are going to look <i class="">approximately</i>&nbsp;the same without doing anything crazy).</font><div class=""><font face="SFHello-Regular" class=""><br class=""></font></div><div class=""><font face="SFHello-Regular" class="">This would not work for </font><font face="SFMono-Regular" class="">Codable</font><font face="SFHello-Regular" class=""> in the general case, however, where subclasses likely need to add additional storage, properties, encoded representations, etc., without equivalent requirements, either via additional protocols or conventions.<br class=""></font><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 3, 2017, at 1:50 AM, Gwendal Roué via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">Le 3 août 2017 à 02:09, Jordan Rose via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">P.S. There's a reason why Decodable uses an initializer instead of a factory-like method on the type but I can't remember what it is right now. I think it's something to do with having the right result type, which would have to be either 'Any' or an associated type if it wasn't just 'Self'. (And if it is 'Self' then it has all the same problems as an initializer and would require extra syntax.) Itai would know for sure.</div></div></blockquote><br class=""></div><div class="">For anyone interested, factory methods *can* retroactivaly be added to existing classes. This is how the SQLite library GRDB.swift is able to decode classes hierarchies like NSString, NSNumber, NSDecimalNumber, etc. from SQLite values:</div><div class=""><br class=""></div><div class="">The protocol for types that can instantiate from SQLite values has a factory method:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">&nbsp; &nbsp; public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures" class=""> DatabaseValueConvertible</span><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(61, 121, 164);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">/// Returns a value initialized from *dbValue*, if possible.</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">static</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> fromDatabaseValue(</span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class=""> dbValue: </span><span style="font-variant-ligatures: no-common-ligatures; color: #20809f" class="">DatabaseValue</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c59a7" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">?</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><div class="">Having Foundation classes implement it uses various techniques:</div><div class=""><br class=""></div><div class="">1. "Casting" (Data to NSData, or NSDate to Date, depending on which type provides the root conformance)</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures" class="">// Workaround Swift inconvenience around factory methods of non-final classes</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> cast&lt;T, U&gt;(</span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class=""> value: </span><span style="font-variant-ligatures: no-common-ligatures; color: #20809f" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #20809f" class="">U</span><span style="font-variant-ligatures: no-common-ligatures" class="">? {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> value </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">as</span><span style="font-variant-ligatures: no-common-ligatures" class="">? </span><span style="font-variant-ligatures: no-common-ligatures; color: #20809f" class="">U</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(61, 121, 164);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(60, 89, 167);" class="">NSData</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> : </span><span style="color: rgb(32, 128, 159); font-variant-ligatures: no-common-ligatures;" class="">DatabaseValueConvertible</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">public</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">static</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> fromDatabaseValue(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">_</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> dbValue: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(32, 128, 159);" class="">DatabaseValue</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(60, 89, 167);" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures;" class="">? {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures" class="">// Use Data conformance</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">guard</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> data = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c59a7" class="">Data</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #20809f" class="">fromDatabaseValue</span><span style="font-variant-ligatures: no-common-ligatures" class="">(dbValue) </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">nil</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #20809f" class="">cast</span><span style="font-variant-ligatures: no-common-ligatures" class="">(data)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures;" class="">// Derives Date conformance from NSDate, for example</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c59a7" class="">ReferenceConvertible</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">where</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">: DatabaseValueConvertible, </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.ReferenceType: DatabaseValueConvertible {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(61, 121, 164);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">public</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">static</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> fromDatabaseValue(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">_</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> dbValue: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(32, 128, 159);" class="">DatabaseValue</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(32, 128, 159);" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures;" class="">? {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;ReferenceType.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(32, 128, 159);" class="">fromDatabaseValue</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(dbValue).</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(60, 89, 167);" class="">flatMap</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;{&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(32, 128, 159);" class="">cast</span><span style="font-variant-ligatures: no-common-ligatures;" class="">($0) }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><br class=""></div><div class="">2. Using magic Foundation initializers (magic because the code below compiles even if those are not *required* initializers). Works for NSNumber, NSDecimalNumber, NSString:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(32, 128, 159);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c59a7" class="">NSNumber</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> : </span><span style="font-variant-ligatures: no-common-ligatures" class="">DatabaseValueConvertible</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="color: rgb(61, 121, 164); font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">public</span><span style="color: rgb(61, 121, 164); font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">static</span><span style="color: rgb(61, 121, 164); font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">func</span><span style="color: rgb(61, 121, 164); font-variant-ligatures: no-common-ligatures;" class=""> fromDatabaseValue(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">_</span><span style="color: rgb(61, 121, 164); font-variant-ligatures: no-common-ligatures;" class=""> dbValue: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(32, 128, 159);" class="">DatabaseValue</span><span style="color: rgb(61, 121, 164); font-variant-ligatures: no-common-ligatures;" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(60, 89, 167);" class="">Self</span><span style="color: rgb(61, 121, 164); font-variant-ligatures: no-common-ligatures;" class="">? {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> dbValue.</span><span style="font-variant-ligatures: no-common-ligatures; color: #20809f" class="">storage</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #20809f" class="">int64</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> int64):</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(value: int64)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #20809f" class="">double</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> double):</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(value: double)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">default</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">nil</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(32, 128, 159);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c59a7" class="">NSString</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> : </span><span style="font-variant-ligatures: no-common-ligatures" class="">DatabaseValueConvertible</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(61, 121, 164);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">public</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">static</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> fromDatabaseValue(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(129, 53, 160);" class="">_</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> dbValue: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(32, 128, 159);" class="">DatabaseValue</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(60, 89, 167);" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures;" class="">? {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// Use String conformance</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">guard</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> string = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3c59a7" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #20809f" class="">fromDatabaseValue</span><span style="font-variant-ligatures: no-common-ligatures" class="">(dbValue) </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">nil</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #8135a0" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(string: string)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div></div><div class=""><br class=""></div><div class="">The magic about Foundation initializers above makes me doubt that this technique is general enough for Decodable to profit from it, though. Yes it runs on Linux, so I'm not even sure if objc runtime is required or not. I'm clueless ???????</div><div class=""><br class=""></div><div class="">Gwendal Roué</div><div class=""><br class=""></div></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>