<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="">Here is a correction to the equivalent declaration. It would be a RawRepresentable String enum to be compatible with serialization mechanisms e.g. JSON. and other representations. Again, the name could be auto-generated to keep the syntax succinct.</div><div class=""><br class=""></div><div class="">…</div><div class=""><br class=""></div><div class="">would be equivalent to</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(185, 45, 93);">class</span><span class=""> </span><span style="color: rgb(135, 78, 254);" class="">MyImage</span><span class=""> {</span></div><div class="" style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);"><span class="" style="color: rgb(0, 0, 0);"> <span class="Apple-tab-span" style="white-space: pre;">        </span></span><span class="" style="color: rgb(185, 45, 93);">enum</span><span class="" style="color: rgb(0, 0, 0);"> </span>ScaleCropFitFill<span class="" style="color: rgb(0, 0, 0);"> : <span style="color: rgb(135, 78, 254);" class="">String </span>{</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="Apple-tab-span" style="white-space: pre;">                </span>case <span class="" style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);"><b class="">Fit</b></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="Apple-tab-span" style="white-space: pre;">                </span>case <span class="" style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);"><b class="">Fill</b></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="Apple-tab-span" style="white-space: pre;">        </span>} </div></div><div class="">...</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On May 31, 2016, at 12:25 PM, Christopher Kornher <<a href="mailto:ckornher@me.com" class="">ckornher@me.com</a>> 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="">Apologies for using you as a relay...<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">Begin forwarded message:</div><br class="Apple-interchange-newline"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">From: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Charlie Monroe via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>><br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Subject: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class=""><b class="">Re: [swift-evolution] Ad hoc enums / options</b><br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Date: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">May 31, 2016 at 11:43:43 AM MDT<br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">To: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Charles Constant <<a href="mailto:charles@charlesism.com" class="">charles@charlesism.com</a>><br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Cc: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Swift Evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>, Christopher Kornher <<a href="mailto:ckornher@me.com" class="">ckornher@me.com</a>><br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Reply-To: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Charlie Monroe <<a href="mailto:charlie@charliemonroe.net" class="">charlie@charliemonroe.net</a>><br class=""></span></div><br class=""><div class=""><span 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; float: none; display: inline !important;" class="">I have mixed feelings about this since it may lead to redeclarations over and over of the same values instead of actually declaring an enum.</span></div></blockquote></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class="">I have two suggested “improvements”</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">1) Make the enum String raw-representable. Name it somehow. This does not affect Erica’s original syntax.</div><div style="margin: 0px; line-height: normal;" class="">2) Force an explicit name.</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">#2 does add to the length of function declarations, so it is a tradeoff. Perhaps the name could be optional, but...</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">#2 would improve debug representations of the value by providing a name that can be found in source code</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">In a full-featured metadata system, it would probably be nice to have a type for the enum to simply the handling of all enums. </div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">#2 is more future-proof. Systems get more complex over time and one use of a type becomes many. </div><div style="margin: 0px; line-height: normal;" class="">The enum type name (auto-generated or required, it makes no difference) would be scoped to the function’s namespace e.g. (fixing the typo) :</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);" class=""><span style="color: #b92d5d" class="">class</span><span style="" class=""> </span>MyImage<span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);" class=""><span style="" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #b92d5d" class="">func</span><span style="" class=""> </span>scaleAndCropImage<span style="" class="">(</span></div><div style="margin: 0px; line-height: normal;" class=""> <span class="Apple-tab-span" style="white-space:pre">                </span>image: UIImage,</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>toSize size: CGSize,</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>operation: <span style="color: rgb(135, 78, 254);" class="">ScaleCropFitFill</span>{ .<span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fit</b></span> | <span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fill</b></span>} = .<span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fit</b></span></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""> <span class="Apple-tab-span" style="white-space:pre">        </span>) -> UIImage {…}</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">would be equivalent to:</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);" class=""><span style="color: #b92d5d" class="">class</span><span style="" class=""> </span>MyImage<span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);" class=""><span style="" class=""> <span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #b92d5d" class="">enum</span><span style="" class=""> </span>ScaleCropFitFill<span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>case <span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fit</b></span></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>case <span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fill</b></span></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>} </div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);" class=""><span style="" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #b92d5d" class="">func</span><span style="" class=""> </span>scaleAndCropImage<span style="" class="">(</span></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>image: UIImage,</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>toSize size: CGSize,</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>operation: <span style="color: #874efe" class="">ScaleCropFitFill</span> = .<span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fit</b></span></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>) -> UIImage {…}</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">There are two ways that an implementation could evolve from having one use of the enum in a call to multiple uses;</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">1) The function is refactored into more functions internal to the original function’s namespace: module/class/struct/enum.</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>In this case, it would be appropriate to leave the enum declaration in function declaration to indicate that this is the only public use of the enum.</div><div style="margin: 0px; line-height: normal;" class="">2) More public functions are created that use the enum</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>In this case, it would be appropriate to declare the enum within the same scope. Existing code would not be affected. Smart editors could provide this refactoring.</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">- Chris K</div></div></div></div></blockquote></div><br class=""></body></html>