<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 Pushkar,<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 29, 2016, at 4:12 AM, Pushkar N Kulkarni via swift-corelibs-dev &lt;<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><font face="Verdana,Arial,Helvetica,sans-serif" size="2" class=""><div class="">Hi there,&nbsp;</div><div class=""><br class=""></div><div class="">I am curious about how an autoupdating type property like `NSTimeZone.local` could be implemented, given that it is a <b class="">value</b> (the type is TimeZone). The requirement essentially is that if the default timezone is changed, the change should reflect in all copies of this value.</div><div class=""><br class=""></div><div class=""><p style="font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#bb2ca2" class="">import</font></span><span style="font-variant-ligatures: no-common-ligatures" class=""> Foundation</span></p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></p><p style="font-size: 14px; line-height: normal; font-family: Menlo;" class=""><font color="#703daa" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#bb2ca2" class="">let</font></span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font class=""> local = </font></span><span style="font-variant-ligatures: no-common-ligatures" class="">NSTimeZone</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font class="">.</font></span><span style="font-variant-ligatures: no-common-ligatures" class="">local</span></font></p><p style="font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#bb2ca2" class="">let</font></span><span style="font-variant-ligatures: no-common-ligatures" class=""> local1 = </span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#4f8187" class="">local</font></span></p><p style="font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#4f8187" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#3d1d81" class="">print</font></span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font class="">(</font></span><span style="font-variant-ligatures: no-common-ligatures;" class="">local</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font class="">) &nbsp;//prints the default TimeZone</font></span><br class=""></font></span></p><p style="font-size: 14px; line-height: normal; font-family: Menlo;" class=""><font color="#4f8187" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#3d1d81" class="">print</font></span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font class="">(</font></span><span style="font-variant-ligatures: no-common-ligatures" class="">local1</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font class="">) //prints the default TimeZone</font></span></font></p><p style="font-size: 14px; line-height: normal; font-family: Menlo;" class=""><font color="#4f8187" class=""><br class=""></font></p><p style="font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#bb2ca2" class="">let</font></span><span style="font-variant-ligatures: no-common-ligatures" class=""> t = </span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#703daa" class="">TimeZone</font></span><span style="font-variant-ligatures: no-common-ligatures" class="">(identifier: </span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#d12f1b" class="">"America/Chicago"</font></span><span style="font-variant-ligatures: no-common-ligatures" class="">)!</span></p><p style="font-size: 14px; line-height: normal; font-family: Menlo;" class=""><font color="#703daa" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">NSTimeZone</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font class="">.</font></span><span style="font-variant-ligatures: no-common-ligatures" class="">default</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font class=""> = </font></span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#4f8187" class="">t</font></span></font></p><p style="font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></p><p style="font-size: 14px; line-height: normal; font-family: Menlo;" class=""><font color="#3d1d81" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font class="">(</font></span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#4f8187" class="">local</font></span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font class="">) &nbsp; &nbsp;//prints "America/Chicago (autoupdatingCurrent)</font></span></font></p><p style="font-size: 14px; line-height: normal; font-family: Menlo;" class=""><font color="#4f8187" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#3d1d81" class="">print</font></span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font class="">(</font></span><span style="font-variant-ligatures: no-common-ligatures" class="">local1) &nbsp;&nbsp;</span>//prints "America/Chicago (autoupdatingCurrent)</font></p></div><div class=""><font face="Verdana,Arial,Helvetica,sans-serif" size="2" class=""><font class=""><font class=""><div class="socmaildefaultfont" dir="ltr"><div class="socmaildefaultfont" dir="ltr"><div class="socmaildefaultfont" dir="ltr"><div dir="ltr" style="font-style: normal;" class=""><font face="Sans Serif, Verdana, Arial, Helvetica, sans-serif" class=""><br class=""></font></div><div dir="ltr" style="font-style: normal;" class=""><br class=""></div><div dir="ltr" style="font-style: normal;" class="">What makes it complicated is that TimeZone is a value type. I hope I am not missing something fundamental here!</div><div dir="ltr" style="font-style: normal;" class=""><br class=""></div><div dir="ltr" style="font-style: normal;" class="">Any ideas or information will be highly appreciated. Thanks!</div></div></div></div></font></font></font></div></font></div></blockquote><div><br class=""></div><div>You’re not missing anything fundamental. We considered this case very carefully before proposing these types as value types. I agree that it’s on the borderline, but in the end having it as a value type was too valuable (no pun intended).</div><div><br class=""></div><div>What we decided is essentially this: the value of the time zone is not its identifier. Instead, abstract it one level. That means that “Autoupdating” can be the actual value. Like an open enumeration.</div><div><br class=""></div><div>Now, nothing in the value type contract says that you cannot have computed properties on a value type. Also, value types are not necessarily “pure”, in the sense that they ignore all external input. What this means for time zone is that its identifier can change depending on user preferences, if its value is “autoupdating". If you set its value to a specific time zone instead, then it does not have the value of “autoupdating" and its computed properties do not behave that way.</div><div><br class=""></div><div>I reflected this contract in the == method as well. Autoupdating time zones are equal to other autoupdating time zones. However, the autoupdating time zone is not equal to America/Chicago, even if the current time zone is America/Chicago.&nbsp;</div><div><br class=""></div><div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" 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=""> la = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">TimeZone</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(identifier: </span><span style="font-variant-ligatures: no-common-ligatures" class="">"America/Los_Angeles”</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) // America/Los_Angeles (current)</span></div><div style="margin: 0px; font-size: 14px; 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=""> tz = </span><span style="font-variant-ligatures: no-common-ligatures" class="">TimeZone</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">autoupdatingCurrent // America/Los_Angeles (autoupdatingCurrent)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">la</span><span style="font-variant-ligatures: no-common-ligatures" class=""> == </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">tz // false</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class=""><div style="margin: 0px; font-size: 14px; 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=""> tz2 = </span><span style="font-variant-ligatures: no-common-ligatures" class="">TimeZone</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">autoupdatingCurrent //&nbsp;</span>America/Los_Angeles (autoupdatingCurrent)</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">tz</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">==</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">tz2 // true</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></span></div></div><div>In the case of Calendar, if you mutate it then it is no longer autoupdating — you have changed its value.</div><div><br class=""></div><div>I’m sure reasonable people could disagree on the direction we chose here, and if we were reinventing the world from scratch I probably would not have added this complication to the API. However, the existing autoupdating concept is used pervasively and I needed a way to fit it into the new system.</div><div><br class=""></div>- Tony</div><div><br class=""><blockquote type="cite" class=""><div class=""><font face="Verdana,Arial,Helvetica,sans-serif" size="2" class=""><div class=""><font face="Verdana,Arial,Helvetica,sans-serif" size="2" class=""><font class=""><font class=""><div class="socmaildefaultfont" dir="ltr"><div class="socmaildefaultfont" dir="ltr"><div class="socmaildefaultfont" dir="ltr"><div dir="ltr" style="font-style: normal;" class=""><br class=""></div><div dir="ltr" style="font-style: normal;" class=""><span style="font-family: 'Sans Serif', Verdana, Arial, Helvetica, sans-serif;" class="">Pushkar N Kulkarni,</span><br class=""></div>
<div dir="ltr" style="font-style: normal;" class=""><font face="Sans Serif, Verdana, Arial, Helvetica, sans-serif" class="">IBM Runtimes</font></div><div dir="ltr" style="font-style: normal;" class=""><font face="Sans Serif, Verdana, Arial, Helvetica, sans-serif" class=""><br class=""></font></div><div dir="ltr" class=""><font face="serif, Times New Roman, Times, serif" class=""><i class="">Simplicity is prerequisite for reliability - Edsger W. Dijkstra</i></font></div>
<div dir="ltr" style="font-style: normal; font-size: 10.5pt; font-family: Arial;" class=""><br class=""></div></div></div></div></font></font></font></div></font><br class="">

_______________________________________________<br class="">swift-corelibs-dev mailing list<br class=""><a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev<br class=""></div></blockquote></div><br class=""></div></body></html>