<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=""><blockquote type="cite" class="">On 10 Apr 2016, at 23:12, Jens Alfke <<a href="mailto:jens@mooseyard.com" class="">jens@mooseyard.com</a>> wrote:</blockquote><blockquote type="cite" class="">You can easily implement your own `sample` property. </blockquote><br class=""><div class="">The very first email of this thread has a link to my example implementation. Here it is again if you mist it: <a href="http://stackoverflow.com/a/30285125/1409907" class="">http://stackoverflow.com/a/30285125/1409907</a>… however, my whole point is that I’d prefer if this important feature came with `Foundation`.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">So far Apple hasn’t added Swift-specific functionality to system frameworks…</blockquote><br class=""></div><div class="">As I already stressed, I certainly do not imagine this to be “Swift-specific”, nor do I see any reason it would need to be. Also, it looks like you’ve missed my previous email in this thread where I give examples of current Foundation extensions of Standard Library types, and where I also make the bare bones of my wish-list rather more explicit.</div><div class=""><br class=""></div><div class="">Please note, though, that my original mail was simply trying to find out if there are people who also wished they had this functionality available upon importing Foundation; if they too would enjoy using it in playgrounds, when teaching, or while testing their code… Imagine opening a blank playground and typing something silly like the following, while fully expecting there to be a `sample` method on arrays, just as there is `componentsSeparatedByString` on strings:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">import</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Foundation</span></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(200, 172, 229);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">String</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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></span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> define: </span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class="">? {</span></div><div style="margin: 0px; line-height: normal; color: rgb(145, 84, 15);" 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: #c8ace5" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">DCSCopyTextDefinition</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span><span style="font-variant-ligatures: no-common-ligatures" class="">CFRangeMake</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #ff2600" class="">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #8f793a" class="">utf16</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #8f793a" class="">count</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)).</span><span style="font-variant-ligatures: no-common-ligatures" class="">map</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">{</span></div><div style="margin: 0px; line-height: normal; color: rgb(145, 84, 15);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>$0.</span><span style="font-variant-ligatures: no-common-ligatures" class="">takeRetainedValue</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">() </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">as</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">String</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>}</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>}</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></span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> trail: </span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">String</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></span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> trail = [</span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">]</span></div><div style="margin: 0px; line-height: normal; color: rgb(145, 84, 15);" 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: #c8ace5" class="">while</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> word = trail.</span><span style="font-variant-ligatures: no-common-ligatures; color: #8f793a" class="">last</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">?.</span><span style="font-variant-ligatures: no-common-ligatures; color: #8f793a" class="">define</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">?.</span><span style="font-variant-ligatures: no-common-ligatures" class="">componentsSeparatedByString</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #64961d" class="">" "</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">).</span><span style="font-variant-ligatures: no-common-ligatures; color: #8f793a" class="">sample</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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>trail.</span><span style="font-variant-ligatures: no-common-ligatures; color: #91540f" class="">append</span><span style="font-variant-ligatures: no-common-ligatures" class="">(word)</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>}</span></div><div style="margin: 0px; line-height: normal; color: rgb(145, 84, 15);" 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: #c8ace5" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> trail.</span><span style="font-variant-ligatures: no-common-ligatures" class="">joinWithSeparator</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #64961d" class="">" "</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) + </span><span style="font-variant-ligatures: no-common-ligatures; color: #64961d" 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>}</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class=""> i </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">in</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ff2600" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">...</span><span style="font-variant-ligatures: no-common-ligatures; color: #ff2600" class="">100</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal; color: rgb(100, 150, 29);" 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: #91540f" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"Random"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #8f793a" class="">trail</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</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="">milos</div><br class=""></div></body></html>