<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yiv2068769552"><div id="yui_3_16_0_1_1474390377637_2359"><div style="color:#000;background-color:#fff;font-family:HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;" id="yui_3_16_0_1_1474390377637_2358"><div id="yiv2068769552"><div id="yiv2068769552yui_3_16_0_1_1474390105070_2659"><div id="yiv2068769552yui_3_16_0_1_1474390105070_2658" style="color:#000;background-color:#fff;font-family:HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;"><div id="yiv2068769552yui_3_16_0_1_1474390105070_2667"><span id="yui_3_16_0_1_1474390377637_3992">I knew it's a bug, hence this email.</span></div><div id="yiv2068769552yui_3_16_0_1_1474390105070_2667"><span><br clear="none"></span></div><div dir="ltr" id="yiv2068769552yui_3_16_0_1_1474390105070_2667">I need input() function to accept user input from within Playground, not from Terminal (command line). I want it on Terminal, I would have used the readLine() function which ser</div><div></div><div id="yiv2068769552yui_3_16_0_1_1474390105070_2663">&nbsp;</div><div class="yiv2068769552signature" id="yiv2068769552yui_3_16_0_1_1474390105070_2657"><div id="yiv2068769552yui_3_16_0_1_1474390105070_2656"><br clear="none"></div>–Mr Bee<div id="yiv2068769552yui_3_16_0_1_1474390105070_7113"><br clear="none"></div></div> <div class="yiv2068769552qtdSeparateBR" id="yiv2068769552yui_3_16_0_1_1474390105070_7114"><br clear="none"><br clear="none"></div></div></div></div><div id="yui_3_16_0_1_1474390377637_2363"> <div style="font-family:HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;" id="yui_3_16_0_1_1474390377637_2362"> <div style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;" id="yui_3_16_0_1_1474390377637_2361"> <div class="yiv2068769552qtdSeparateBR" id="yui_3_16_0_1_1474390377637_2360"><br clear="none"><br clear="none"></div><div class="yiv2068769552yqt1263912482" id="yiv2068769552yqtfd13002"><div class="yiv2068769552yqt1777114722" id="yiv2068769552yqtfd80457"><div dir="ltr" id="yui_3_16_0_1_1474390377637_2365"><font size="2" face="Arial" id="yui_3_16_0_1_1474390377637_2364"> Pada Selasa, 20 September 2016 21:13, Zhao Xin &lt;owenzx@gmail.com&gt; menulis:<br clear="none"></font></div>  <br clear="none"><br clear="none"> <div class="yiv2068769552y_msg_container" id="yui_3_16_0_1_1474390377637_2369"><div id="yiv2068769552"><div id="yui_3_16_0_1_1474390377637_2368"><div dir="ltr" id="yui_3_16_0_1_1474390377637_2367"><div class="yiv2068769552gmail_default" style="font-family:georgia, serif;" id="yui_3_16_0_1_1474390377637_2366">I test you code in command line `swiftc main.swift` and in macOS Command Line Tool app.</div><div class="yiv2068769552gmail_default" style="font-family:georgia, serif;" id="yui_3_16_0_1_1474390377637_2370"><br clear="none"></div><div class="yiv2068769552gmail_default" style="font-family:georgia, serif;" id="yui_3_16_0_1_1474390377637_2371">Here is the main.swift:</div><div class="yiv2068769552gmail_default" style="font-family:georgia, serif;" id="yui_3_16_0_1_1474390377637_2372"><br clear="none"></div><div class="yiv2068769552gmail_default" id="yui_3_16_0_1_1474390377637_2375"><div style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;" id="yui_3_16_0_1_1474390377637_2374"><span style="color:rgb(4,51,255);">import</span><span style="" id="yui_3_16_0_1_1474390377637_2373"> Foundation</span></div>
<div style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px;"><span style=""></span><br clear="none"></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="color:rgb(4,51,255);">import</span><span style=""> Foundation</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px;"><span style=""></span><br clear="none"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="color:rgb(4,51,255);">func</span><span style=""> input() -&gt; </span><span style="color:rgb(52,149,175);">String</span><span style=""> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,149,175);"><span style="color:rgb(0,0,0);">&nbsp; &nbsp; </span><span style="color:rgb(4,51,255);">let</span><span style="color:rgb(0,0,0);"> keyboard&nbsp; = </span><span style="">FileHandle</span><span style="color:rgb(0,0,0);">.</span><span style="">standardInput</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">&nbsp; &nbsp; </span><span style="color:rgb(4,51,255);">let</span><span style=""> inputData = keyboard.</span><span style="color:rgb(52,149,175);">availableData</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">&nbsp; &nbsp; </span><span style="color:rgb(4,51,255);">let</span><span style=""> strData &nbsp; = </span><span style="color:rgb(52,149,175);">String</span><span style="">(data: inputData, encoding: .</span><span style="color:rgb(52,149,175);">utf8</span><span style="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">&nbsp; &nbsp; </span><span style="color:rgb(4,51,255);">return</span><span style=""> strData!</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px;"><span style=""></span><br clear="none"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="color:rgb(4,51,255);">func</span><span style=""> write(</span><span style="color:rgb(4,51,255);">_</span><span style=""> txt: </span><span style="color:rgb(52,149,175);">String</span><span style="">) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">&nbsp; &nbsp; </span><span style="color:rgb(52,149,175);">print</span><span style="">(txt, terminator: </span><span style="color:rgb(180,38,26);">""</span><span style="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px;"><span style=""></span><br clear="none"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="color:rgb(4,51,255);">func</span><span style=""> read() -&gt; </span><span style="color:rgb(52,149,175);">String</span><span style=""> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,149,175);"><span style="color:rgb(0,0,0);">&nbsp; &nbsp; </span><span style="color:rgb(4,51,255);">let</span><span style="color:rgb(0,0,0);"> c = </span><span style="">CharacterSet</span><span style="color:rgb(0,0,0);">.</span><span style="">whitespacesAndNewlines</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,149,175);"><span style="color:rgb(0,0,0);">&nbsp; &nbsp; </span><span style="color:rgb(4,51,255);">return</span><span style="color:rgb(0,0,0);"> </span><span style="">input</span><span style="color:rgb(0,0,0);">().</span><span style="">trimmingCharacters</span><span style="color:rgb(0,0,0);">(in: c)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px;"><span style=""></span><br clear="none"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,143,0);"><span style="">/* main program */</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px;"><span style=""></span><br clear="none"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(180,38,26);"><span style="color:rgb(52,149,175);">write</span><span style="color:rgb(0,0,0);">(</span><span style="">"Enter your name: "</span><span style="color:rgb(0,0,0);">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="color:rgb(4,51,255);">let</span><span style=""> s = </span><span style="color:rgb(52,149,175);">read</span><span style="">()</span></div><div style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;">





















</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(180,38,26);"><span style="color:rgb(52,149,175);">print</span><span style="color:rgb(0,0,0);">(</span><span style="">"You name is </span><span style="color:rgb(0,0,0);">\</span><span style="">(</span><span style="color:rgb(52,149,175);">s</span><span style="">)"</span><span style="color:rgb(0,0,0);">)</span></div><div style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(180,38,26);"><span style="color:rgb(0,0,0);"><br clear="none"></span></div><div style="margin:0px;line-height:normal;"><span style=""><font face="georgia, serif" color="#000000">It turns out that the input request was ran before the `</font></span><font color="#000000" face="georgia, serif">write("Enter your name: ")`. I don't why. Maybe it is a bug?</font></div><div style="margin:0px;line-height:normal;"><font color="#000000" face="georgia, serif"><br clear="none"></font></div><div style="margin:0px;line-height:normal;"><font color="#000000" face="georgia, serif">Here is my output in terminal:</font></div><div style="margin:0px;line-height:normal;"><font color="#000000" face="georgia, serif"><br clear="none"></font></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">$ swiftc main.swift&nbsp;</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">$ ./main&nbsp;</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">abc</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">Enter your name: You name is abc</span></div><div style="margin:0px;line-height:normal;">




</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style="">$&nbsp;</span></div><div style="margin:0px;line-height:normal;"><font color="#000000" face="georgia, serif"><br clear="none"></font></div><div style="margin:0px;line-height:normal;" id="yui_3_16_0_1_1474390377637_3953"><font color="#000000" face="georgia, serif">As you can see, the program asked me to input my name before it showed the notification. In playground, the situation is alike.&nbsp;</font></div><div style="margin:0px;line-height:normal;" id="yui_3_16_0_1_1474390377637_3954"><font color="#000000" face="georgia, serif"><br clear="none"></font></div><div style="margin:0px;line-height:normal;" id="yui_3_16_0_1_1474390377637_3956"><font color="#000000" face="georgia, serif" id="yui_3_16_0_1_1474390377637_3955">However, if the code is running as a command line tool, created by Xcode -&gt; Create a new project -&gt; macOS, command line tool, everything works fine.</font></div><div style="margin:0px;line-height:normal;" id="yui_3_16_0_1_1474390377637_3957"><font color="#000000" face="georgia, serif"><br clear="none"></font></div><div style="margin:0px;line-height:normal;" id="yui_3_16_0_1_1474390377637_3958"><font color="#000000" face="georgia, serif">Zhaoxin</font></div></div></div><div class="yiv2068769552gmail_extra" id="yui_3_16_0_1_1474390377637_3959"><br clear="none"><div class="yiv2068769552gmail_quote" id="yui_3_16_0_1_1474390377637_3969">On Sun, Sep 18, 2016 at 9:16 PM, Mr Bee via swift-users <span dir="ltr">&lt;<a rel="nofollow" shape="rect" ymailto="mailto:swift-users@swift.org" target="_blank" href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt;</span> wrote:<br clear="none"><blockquote class="yiv2068769552gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;" id="yui_3_16_0_1_1474390377637_3968"><div class="yiv2068769552yqt1359009922" id="yiv2068769552yqt75043"><div id="yui_3_16_0_1_1474390377637_3967"><div style="color:#000;background-color:#fff;font-family:HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;" id="yui_3_16_0_1_1474390377637_3966"><div><span>Hi all,</span></div><div><span><br clear="none"></span></div><div><span>Another question.&nbsp;</span>I used to use this snippet to read keyboard input from XCode's Playground. And it used to work very well. Today, I just updated my XCode to v.8 and Swift v.3. After a little bit modification here and there due to Swift 3 incompatibility, I got this code compiled without error. But it doesn't work. No keyboard input is taken. It just stucks.</div><div><br clear="none"></div><div dir="ltr">Here's the code:</div><div dir="ltr"><br clear="none"></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span style="color:#35568a;">import</span><span> Foundation</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;min-height:14px;"><span></span><br clear="none"></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span style="color:#35568a;">func</span><span> input() -&gt; </span><span style="color:#c35900;">String</span><span> {</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span>&nbsp; </span><span style="color:#35568a;">let</span><span> keyboard&nbsp; = </span><span style="color:#c35900;">FileHandle</span><span>.</span><span style="color:#587ea8;">standardInput</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span>&nbsp; </span><span style="color:#35568a;">let</span><span> inputData = keyboard.</span><span style="color:#587ea8;">availableData</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span>&nbsp; </span><span style="color:#35568a;">let</span><span> encoding&nbsp; = </span><span style="color:#c35900;">String</span><span>.</span><span style="color:#c35900;">Encoding</span><span>(rawValue: </span><span style="color:#c35900;">String</span><span>.</span><span style="color:#c35900;">Encoding</span><span>.</span><span style="color:#587ea8;">utf8</span><span>.</span><span style="color:#587ea8;">rawValue</span><span>)</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span>&nbsp; </span><span style="color:#35568a;">let</span><span> strData &nbsp; = </span><span style="color:#c35900;">String</span><span>(data: inputData, encoding: encoding)</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span>&nbsp; </span><span style="color:#35568a;">return</span><span> strData! </span><span style="color:#35568a;">as</span><span> </span><span style="color:#c35900;">String</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span>}</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;min-height:14px;"><span></span><br clear="none"></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span style="color:#35568a;">func</span><span> write(</span><span style="color:#35568a;">_</span><span> txt: </span><span style="color:#c35900;">String</span><span>) {</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span>&nbsp; </span><span style="color:#587ea8;">print</span><span>(txt, terminator: </span><span style="color:#e82300;">""</span><span>)</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span>}</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;min-height:14px;"><span></span><br clear="none"></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span style="color:#35568a;">func</span><span> read() -&gt; </span><span style="color:#c35900;">String</span><span> {</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;color:rgb(88,126,168);"><span style="color:#000000;">&nbsp; </span><span style="color:#35568a;">let</span><span style="color:#000000;"> c = </span><span style="color:#c35900;">CharacterSet</span><span style="color:#000000;">.</span><span>whitespacesAndNew lines</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;color:rgb(88,126,168);"><span style="color:#000000;">&nbsp; </span><span style="color:#35568a;">return</span><span style="color:#000000;"> </span><span>input</span><span style="color:#000000;">().</span><span>trimmingCharacters</span><span style="color:#000000;">(in: c)</span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;min-height:14px;">}<br clear="none"></div><div dir="ltr"><span><br clear="none"></span></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span style="color:rgb(207,135,36);">/* main program */</span><br clear="none"></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;min-height:14px;"><span></span><br clear="none"></div><div style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;color:rgb(232,35,0);"><span style="color:#587ea8;">write</span><span style="color:#000000;">(</span><span>"Enter your name: "</span><span style="color:#000000;">)</span></div><div dir="ltr">





























</div><div dir="ltr" style="margin-top:0px;margin-bottom:0px;font-size:12px;line-height:normal;font-family:Menlo;"><span style="color:#35568a;">let</span><span> s = </span><span style="color:#587ea8;">read</span><span>()</span></div><div></div><div>&nbsp;</div><div id="yui_3_16_0_1_1474390377637_3965"><div id="yui_3_16_0_1_1474390377637_3964"><div>So, does anyone know how to make it works (again)? Thank you.</div><div id="yui_3_16_0_1_1474390377637_3963"><br clear="none"></div><div dir="ltr">Regards,</div></div><div><br clear="none"></div>–Mr Bee<div><br clear="none"></div></div></div></div></div><br clear="none">______________________________ _________________<br clear="none">
swift-users mailing list<br clear="none">
<a rel="nofollow" shape="rect" ymailto="mailto:swift-users@swift.org" target="_blank" href="mailto:swift-users@swift.org">swift-users@swift.org</a><br clear="none">
<a rel="nofollow" shape="rect" target="_blank" href="https://lists.swift.org/mailman/listinfo/swift-users">https://lists.swift.org/ mailman/listinfo/swift-users</a><br clear="none">
<br clear="none"></blockquote></div><br clear="none"></div></div></div><br clear="none"><br clear="none"></div>  </div></div></div><div class="yiv2068769552yqt1777114722" id="yiv2068769552yqtfd66128"><div class="yiv2068769552yqt1263912482" id="yiv2068769552yqtfd76942"> </div></div></div><div class="yiv2068769552yqt1777114722" id="yiv2068769552yqtfd65713"><div class="yiv2068769552yqt1263912482" id="yiv2068769552yqtfd32484">  </div></div></div></div></div></div></div></body></html>