<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="">Statically typed persistent storage solutions are far and away superior to Core Data. Whether you’re looking for queries that are correct-by-construction with DSLs or looking for easy model construction and composability, or even just modularity and ease of use. The ability to have the type system check your work is not antithetical to the idea of marshaling data - if anything it’s far more effective. </div><div class=""><br class=""></div><div class="">- Begin with a protocol for serializable things to teach the framework about your schema:</div><div class=""><br class=""></div><div class=""><font color="#333333" face="-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol" class=""><span style="font-size: 14px;" class="">/// decode • encode == id<br class="">public protocol Serializable {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Encode a value.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var serialize : Put<Format> { get }<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Decode a value.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>static var deserialize : Get<Self> { get }<br class="">}</span></font><table class="js-file-line-container highlight tab-size" data-tab-size="8" style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;"><tbody style="box-sizing: border-box;" class=""><tr style="box-sizing: border-box;" class=""><td id="L27" class="blob-num js-line-number" data-line-number="27" style="box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td></tr></tbody></table><br class=""></div><div class="">- Provide combinators and functions attached to `Get` and `Put` to make [de]serializing aggregates easy. </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: #ba2da2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Person : </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Equatable</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=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> age : </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UInt32</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=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> weight : </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UInt32</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">}</span></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">Person</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> : </span><span style="font-variant-ligatures: no-common-ligatures" class="">Serializable</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">static</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> deserialize : </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Get</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Person</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(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span><span style="font-variant-ligatures: no-common-ligatures" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Get</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">zip</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">                        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UInt32</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">deserialize</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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=""><span class="Apple-tab-span" style="white-space:pre">                </span>).</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">map</span><span style="font-variant-ligatures: no-common-ligatures" class="">(<font color="#4f8187" class="">Person</font></span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">init</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=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</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=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> serialize : </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Put<Person></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="color: rgb(0, 0, 0); font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span><span style="color: rgb(186, 45, 162); font-variant-ligatures: no-common-ligatures;" class="">return</span><span style="color: rgb(0, 0, 0); font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="color: rgb(186, 45, 162); font-variant-ligatures: no-common-ligatures;" class="">self</span><span style="color: rgb(0, 0, 0); font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#4f8187" class="">age</font></span><span style="color: rgb(0, 0, 0); font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color: rgb(79, 129, 135); font-variant-ligatures: no-common-ligatures;" class="">serialize</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(0, 0, 0); font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>.</span><span style="color: rgb(49, 89, 93); font-variant-ligatures: no-common-ligatures;" class="">then</span><span style="color: rgb(0, 0, 0); font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="color: rgb(186, 45, 162); font-variant-ligatures: no-common-ligatures;" class="">self</span><span style="color: rgb(0, 0, 0); font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#4f8187" class="">weight</font></span><span style="color: rgb(0, 0, 0); font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color: rgb(79, 129, 135); font-variant-ligatures: no-common-ligatures;" class="">serialize</span><span style="color: rgb(0, 0, 0); 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=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</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="">}</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">- Select a backend</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: #ba2da2" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> SqlBackend : <span style="color: rgb(112, 61, 170);" class="">Backend</span> {</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><font color="#ba2da2" class="">func p</font></span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">repare(statement : </span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">String)</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""> -> </span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Statement { }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> insert<Entity : </span>Serializable<span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">>(_ entity : </span><span style="font-variant-ligatures: no-common-ligatures;" class="">Entity)</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> -> Result { }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// etc.</span></div></span></div><div class="">}</div><div class=""><br class=""></div><div class="">- Maybe put a little DSL on top if you’re feeling cheeky</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> p : </span><span style="font-variant-ligatures: no-common-ligatures" class="">SQLQuery</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><[</span><span style="font-variant-ligatures: no-common-ligatures" class="">Person</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">]> =</span></div></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>select <|</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>from { p </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">in</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>(where_ <| exists <|</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>from { (p : </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Person</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">SQLQuery</span><span style="font-variant-ligatures: no-common-ligatures" class=""><()> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">in</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">                                </span>where_(val(p.age) <= val(</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">18</span><span style="font-variant-ligatures: no-common-ligatures" class="">))</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>}).then(SQLQuery<</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Person</span><span style="font-variant-ligatures: no-common-ligatures" class="">>.pure(p))</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div></div><div class=""><br class=""></div><div class="">- Serve immediately</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Sep 27, 2016, at 12:29 PM, Ricardo Parada <<a href="mailto:rparada@mac.com" class="">rparada@mac.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" 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 26, 2016, at 5:32 PM, Robert Widmann via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; 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; direction: inherit;" class="">No, and I think moving towards a more dynamic Swift now without as-of-yet-seen significant justification would be a mistake. Swift should be as static as possible. We should be making every attempt to pare down the existing runtime and quietly transition those that rely on dynamism to checked reflection (yes, that is not in fact an oxymoron). The more the compiler knows about your program, the better it does. Period.</div><br class="Apple-interchange-newline"></div></blockquote></div>How would you implement something like Core Data in pure Swift on the server where the Obj-C runtime is not available?<div class=""><br class=""></div><div class=""><br class=""></div></div></div></blockquote></div><br class=""></body></html>