<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="">Hi there,<div class=""><br class=""></div><div class="">I've recently developed a wrapper around UserDefaults (formerly known as NSUserDefaults), which adds type safety and omits the need for stringified API calls. I’m not sure if this development fits in here, but anyway I’m going to give it a try:</div><div class=""><br class=""></div><div class="">Since I use UserDefaults for storing preference settings most of the time, I simply called the wrapper class Setting. A typical declaration would look like:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">var</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">&nbsp;favoriteLanguage =&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">Setting</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">&lt;</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">String</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">&gt;(key:&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"favoriteLanguage"</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">, defaultValue:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(209, 47, 27);">"ObjectiveC</span><font color="#d12f1b" face="Menlo" class=""><span class="" style="font-size: 11px;">“</span></font><font face="Menlo" class=""><span class="" style="font-size: 11px;">)</span></font></span></div></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;">you can change a setting by simply calling:</div><div class="" style="margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(79, 129, 135); font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">favoriteLanguage</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">.</span><span class="" style="color: rgb(79, 129, 135); font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">value</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">&nbsp;=&nbsp;</span><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 11px;">"Swift</span><font color="#d12f1b" face="Menlo" class=""><span class="" style="font-size: 11px;">“</span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#d12f1b" face="Menlo" class=""><span class="" style="font-size: 11px;"><br class=""></span></font></div><div class="" style="margin: 0px; line-height: normal;">The Setting type is generic and will accept any class or struct, which conforms to the</div><div class="" style="margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);"><span class="" style="font-variant-ligatures: no-common-ligatures;">UserDefaultConvertible</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">protocol (which I also created). This allows enums (which have a UserDefaultConvertible RawValue) to be stored into user defaults like this:</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">enum</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">&nbsp;Languages:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures;">UserDefaultConvertible</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">&nbsp;{</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;Swift =&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">0</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;ObjectiveC</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;Java</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">favoriteLanguage =&nbsp;<span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">Setting</span>&lt;<span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">Languages</span>&gt;(key:&nbsp;<span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"favoriteLanguage"</span>, defaultValue: .<span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);">ObjectiveC</span>)</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="" style="font-variant-ligatures: no-common-ligatures;">favoriteLanguage</span>.<span class="" style="font-variant-ligatures: no-common-ligatures;">value</span>&nbsp;= .<span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);">Swift</span></span></div></span></div></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);"><span class="" style="color: rgb(209, 47, 27);"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="">With SE-0143 being implemented into Swift 4, the above approach would also work nicely with Arrays and Dictionaries. For any implementation details please refer to&nbsp;</span><a href="https://github.com/oliverschaefer/Settings" class="">https://github.com/oliverschaefer/Settings</a>. Before proceeding with a SE proposal, I’d like to hear your opinion. So thanks for taking your time to look at my code in advance.</div><div class="" style="margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;">Cheers,</div><div class="" style="margin: 0px; line-height: normal;">Oliver&nbsp;</div></div></body></html>