<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 阿伯拉底 on Medium]]></title>
        <description><![CDATA[Stories by 阿伯拉底 on Medium]]></description>
        <link>https://medium.com/@goodfit8?source=rss-e0df7febb671------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1gBNxPuX-0lVsCOAexZZhg.jpeg</url>
            <title>Stories by 阿伯拉底 on Medium</title>
            <link>https://medium.com/@goodfit8?source=rss-e0df7febb671------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 01:24:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@goodfit8/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[逐夢棋緣 — 西洋棋App第一集]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E9%80%90%E5%A4%A2%E6%A3%8B%E7%B7%A3-%E8%A5%BF%E6%B4%8B%E6%A3%8Bapp%E7%AC%AC%E4%B8%80%E9%9B%86-2a23d079f6c9?source=rss-e0df7febb671------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a23d079f6c9</guid>
            <dc:creator><![CDATA[阿伯拉底]]></dc:creator>
            <pubDate>Wed, 19 Sep 2018 14:01:01 GMT</pubDate>
            <atom:updated>2018-09-19T14:01:01.759Z</atom:updated>
            <content:encoded><![CDATA[<p>逐夢棋緣是2016年的一部電影。描述在烏干達這個國家(不是瓦甘達，那是黑豹)，一位貧民窟的女孩子藉由西洋棋改善家中經濟狀況的故事。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*tNAGRvNfdTNGH8IL2iP-qg.jpeg" /></figure><p>當然廣義地說，這是一部勵志片，但它的梗不會老，因為這部片對於人性的描寫算深刻，演員的表演也都很自然，還有一個很重要的就是加入了西洋棋這個元素。劇中的名言：「在西洋棋裡，小卒也能變英雄，所以我才喜歡下西洋棋。」因此，今天這篇文章，我就把主題放在小卒。</p><p>各位若不知道西洋棋的規則，只要先知道小卒的走法。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LYV8ETTSTNn1FJQSHr0VSQ.png" /></figure><p>重點在於一次只能走一格，要吃對方棋子時是向位於斜前方的格子吃。小卒的英文是pawn，一次只能前進一格，看似平凡無奇，但是若走到底線就可以升變成皇后、城堡、騎士、主教，任選一種。這種鹹魚翻身的故事，非常勵志，所以逐夢棋緣就是基於這樣的想法，拍出一個脫離貧民窟，邁向富貴人生的電影。我本人也很喜歡下西洋棋，那為什麼我沒有因為西洋棋變富有呢？當然撇開我自己所投入的時間還不夠多的原因之外，在台灣並沒有這項運動的市場也是主要的因素，之前就曾看過一篇文章寫到在台灣象棋練到五段也只能去賣滷味XD。OK，閒話到此為止，今天其實重點是要介紹我的西洋棋App有了初步的成果，就是我完成小卒的走法了。執行動畫如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*eh75Pd17kTB9piQb6UNaHg.gif" /></figure><p>截圖如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*Kh1wyxG5f3-KMEtthyfpUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*iD7xoZ1SoG37aqfw0i1t6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*bYQ7YeteIgPbXLvl49KVbA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*ve0rPaUNMinT86StTYxPtg.png" /></figure><p>GitHub如下：</p><p><a href="https://github.com/justinlin0819/Chess">justinlin0819/Chess</a></p><p>西洋棋有6個兵種，我光寫小卒的走法程式碼就落落長了。我接下來一方面要思考如何縮短程式碼，一方面要完成其它5個兵種的走法，估計還有很長一段路，所以今天我先發表第一集分享給大家。最後再送大家一句「逐夢棋緣」的台詞：「不要輕易傾倒國王，仔細觀察就能找出活路。」</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a23d079f6c9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E9%80%90%E5%A4%A2%E6%A3%8B%E7%B7%A3-%E8%A5%BF%E6%B4%8B%E6%A3%8Bapp%E7%AC%AC%E4%B8%80%E9%9B%86-2a23d079f6c9">逐夢棋緣 — 西洋棋App第一集</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[寫在彼得潘iOS App課程結束之後]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%AF%AB%E5%9C%A8%E5%BD%BC%E5%BE%97%E6%BD%98ios-app%E8%AA%B2%E7%A8%8B%E7%B5%90%E6%9D%9F%E4%B9%8B%E5%BE%8C-e3693a213bfb?source=rss-e0df7febb671------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3693a213bfb</guid>
            <dc:creator><![CDATA[阿伯拉底]]></dc:creator>
            <pubDate>Sun, 09 Sep 2018 04:56:58 GMT</pubDate>
            <atom:updated>2018-09-09T04:56:58.882Z</atom:updated>
            <content:encoded><![CDATA[<p>會來上彼得潘的iOS App程式設計課程是因為想擁有另一個專業。雖然自己已經是多才多藝了，但根據時下最流行的一個詞，斜槓青年，才藝永遠不嫌多，所以即使已經橫跨Project Manager、Chess Player、Youtuber的領域，還是想再多學一點。而且自己有評估過這麼多斜槓，真正能為自己帶來金流的不多。經過我自己對市場的評估，認為iOS App Designer是真的可以帶來金流，所以集滿好幾個\\\\\還是其次，可以為自己帶來金流的\才是有用的。</p><p>這門課的老師是一位年輕且有活力，幽默且風趣的帥哥(希望這樣之後可以幫我介紹一些案子來XD)。而且難得的是上完這期課程，之後要重聽，彼得潘是不收費的(聽說十月底就要再開課了)。另外就是彼得潘把Swift和Xcode的使用方式幾乎完整介紹了，至少涵蓋的主題比市面上的書籍多很多，所以繳這個學費真的是值回票價。</p><p>而我認為最難能可貴的是彼得潘要求同學交的作業一定要附上程式碼，而且要能供所有同學下載。這真是讓我最感動的，何以如此說？請先看彼得潘的這篇文章：</p><p><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/%E4%B9%9F%E8%A8%B1%E6%88%91%E5%80%91%E5%8F%AF%E4%BB%A5%E5%A4%9A%E6%8A%8A%E7%84%A6%E9%BB%9E%E6%94%BE%E5%9C%A8%E5%BE%8C%E9%9D%A2-e1c0c2cbccf7">把聚光燈留給後面的朋友</a></p><p>我們的世界太多歌頌天才的故事，卻對於後面10%，甚至40%的人，提供的幫助實在太少。這是人的天性，人們總愛錦上添花，不愛雪中送炭。所以分享程式碼至少提供給後面的朋友一個追趕的機會，不會寫就先抄，不理解就先背。我本身過去也是從後面10%一路努力到今天，所以深有同感。</p><p>其實早在2015年，我就想自己開發iOS App，但是當時市面上的書籍真的更新太慢，跟不上Swift語法的改版，以及Xocde介面的改版，自己看書學真的蠻挫折的，記得當時光想要寫個解析JSON格式的Open Data就無法完成。沒想到今年在上了彼得潘的課程後，寫出了氣象人這個天氣預報的App，現在的我真的認為解析JSON原來就是這麼回事而已，小菜一碟。之前沒follow到氣象人的同學可以參考以下兩篇，總共有兩集。</p><ul><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/%E6%B0%A3%E8%B1%A1%E4%BA%BA-a021b7e526ec">氣象人</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/%E6%B0%A3%E8%B1%A1%E4%BA%BA%E7%BA%8C%E9%9B%86-57159ccd0dd2">氣象人續集</a></li></ul><p>另外就是上了彼得潘的課程後，完成了生平第一個電子書的程式，為什麼這麼說，因為我雖然是資工科系畢業，但之前不論是用C、Visual Basic，都還沒寫過電子書的程式。當然不是說那些程式語言不能寫出電子書，只是Swift在某些功能的App上，真的可以很迅速地開發出一個成果，而彼得潘在一開始的前幾堂課就把這個訣竅告訴大家了。</p><p>當初在報名時，我原本以為在班上應該是有很多資工背景的程式高手，結果發現還蠻多不是本科系或是沒有程式設計背景的，甚至有些同學對於程式語言的理解有些困難，這裡我想順便分享我最近重新對程式這門學問的理解給大家。</p><p>所謂程式，就是你和電腦對話的語言，只是這個對話比較特別，基本上是單向的，因為電腦不太會回應你每一句程式，通常只有在你寫錯時才會告訴你這一句話說錯了。但電腦真的是很聽話的，你要他做什麼，他就做什麼，只要你說的語言完全符合邏輯。如果你先把冷冰冰的電腦印象拋開，把他當成一個人，聽話的人，或者就說是工具人，他是會完全照你的吩咐去做事的，那麼其實電腦就跟我們人類一樣。何以如此說？因為我們也是遵從這個世界、國家、社會、公司、學校提供的環境、法令、政策在做事。只是我們可以有意志決定自己現在該做什麼，但是我們無法做出脫離我們所處的環境所制定的法規。所以如果有個台灣男人的protocol，會如以下所寫的：</p><pre>protocol 台灣男人 {</pre><pre>   func 12年國民教育()</pre><pre>   func 納稅()</pre><pre>   func 服兵役()</pre><pre>}</pre><p>然後每個出生的台灣男人都必須follow這個protocol，實作一種類別的人。我們知道這社會上有各式各樣類型的人，有人就是會逃漏稅、有人就是會逃兵，有人就是高中唸四年，這就是最後實作的類別不同。比如對於一個會逃漏稅的奸商，這個Class就會像這樣：</p><pre>class 逃漏稅人: 台灣男人 {</pre><pre>   func 12年國民教育() {</pre><pre>     唸完12年畢業 <br>   }</pre><pre>   func 納稅() {</pre><pre>     逃漏稅<br>   }</pre><pre>   func 服兵役() {</pre><pre>     按時服完兵役<br>   }</pre><pre>}</pre><p>這個類別生成的台灣男人寫法如下：</p><pre>var 奸商: 台灣男人 = 逃漏稅人()</pre><p>所以每年五月，這個奸商都會執行這個function：</p><pre>奸商.納稅()</pre><p>外表是納稅，而實際內容就是逃漏稅。</p><p>但社會上還是有一些奉公守法的好國民，class就會像這樣：</p><pre>class 好國民: 台灣男人 {</pre><pre>   func 12年國民教育() {</pre><pre>     唸完12年畢業<br>   }</pre><pre>   func 納稅() { </pre><pre>     誠實納稅<br>   }</pre><pre>   func 服兵役() {</pre><pre>     按時服完兵役<br>   }</pre><pre>}</pre><p>如果這個奸商哪一天良心發現，要遵守國家的稅法，誠實納稅，那麼他也會是一個好國民，這時他就變成這類型的人：</p><pre>奸商 = 好國民()</pre><p>同樣地，每年五月，這個奸商都會執行這個function：</p><pre>奸商.納稅()</pre><p>這時侯執行的實際內容就是誠實納稅。</p><p>為什麼奸商可以直接變成好國民？因為他是follow台灣男人的protocol，所以只要是follow台灣男人的protocol的類型的人，都是奸商可以成為的人。透過上面的例子，是不是就把難以理解的protocol搞懂了？</p><p>另外，我們班上的台灣男人都是好國民，會接受國民教育、誠實納稅與服兵役，但我們的人生當然不會只做這些事，我們也曾經學過很多專業與才能，所以我們就像是繼承了好國民的義務之後又發展了一些能力，比如會投三分球和桌球的彼得潘：</p><pre>class 三分球與桌球王子: 好國民 {</pre><pre>   func 12年國民教育() {</pre><pre>     唸完12年畢業<br>   }</pre><pre>   func 納稅() {</pre><pre>     誠實納稅<br>   }</pre><pre>   func 服兵役() {</pre><pre>     按時服完兵役<br>   }</pre><pre>   func 三分球 {</pre><pre>     三分球命中率60%</pre><pre>   }<br></pre><pre>   func 桌球 {<br>     殺球強勁</pre><pre>   }</pre><pre>}</pre><p>這個類別生成的好國民寫法如下：</p><pre>var 彼得潘 = 三分球與桌球王子()</pre><p>所以下次和彼得潘打桌球時，他就會執行這個function：</p><pre>彼得潘.桌球()</pre><p>這時就會被強勁殺球給KO了，這樣子又搞懂繼承的觀念了。</p><p>而像是if…else，就像是我們每天做任何事都是有條件地去選擇自己要做的事，這跟電腦接受程式後的思維是一樣的。比如我們每天都在做的幾件重要的事，判斷這時要做什麼的寫法如下：</p><pre>if 上班時間到 {</pre><pre>   我.起床()</pre><pre>} else if 肚子餓 {<br></pre><pre>   我.吃飯()</pre><pre>} else if 睡覺時間到 {</pre><pre>   我.睡覺()</pre><pre>} else {</pre><pre>   我.工作() </pre><pre>}</pre><p>看了之後，有沒有覺得我們的每天生活蠻無趣的XD。</p><p>而迴圈就像是我們每天在重複做的事情一樣，就像我們每天都會去上班，但是遇到週末就會休息，到了週一又繼續這樣的生活，所以在我們身上的程式就會像這樣寫：</p><pre>for 今天星期幾 in 星期一...星期日 {<br></pre><pre>   if 今天星期幾 == 星期六 || 今天星期幾 == 星期日 {</pre><pre>      continue<br>   }</pre><pre>   我.上班()</pre><pre>}</pre><p>注意這裡使用了continue的指令，這是不執行迴圈之後的動作直接跳到下一個迴圈的意思。但是以上的程式只描述了一週的行為，要描述我們一年365天的行為就必須這樣寫(假設一年有48週)：</p><pre>for i in 1...48 {</pre><pre>   for 今天星期幾 in 星期一...星期日 {</pre><pre>      if 今天星期幾 == 星期六 || 今天星期幾 == 星期日 {</pre><pre>         continue<br>      }</pre><pre>      我.上班()</pre><pre>   }</pre><pre>   今天星期幾 = 星期一<br>}</pre><p>看了之後，有沒有更覺得我們的每年生活蠻無趣的XD。</p><p>以上的說明是為了讓程式語言背景比較薄弱的同學，可以用非常生活化的想法，來理解程式語言真正的含義。其實人、電腦，都是有腦的，所以要做任何事必須follow的邏輯基本上是一樣的，我個人認為那些發明程式語言、物件導向的先進，應該也是用這樣的思維在設計這些理論的。總之，敬祝各位同學在往後的學習之路上更精進，也謝謝彼得潘這兩個月來的指導。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3693a213bfb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%AF%AB%E5%9C%A8%E5%BD%BC%E5%BE%97%E6%BD%98ios-app%E8%AA%B2%E7%A8%8B%E7%B5%90%E6%9D%9F%E4%B9%8B%E5%BE%8C-e3693a213bfb">寫在彼得潘iOS App課程結束之後</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[氣象人續集]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E6%B0%A3%E8%B1%A1%E4%BA%BA%E7%BA%8C%E9%9B%86-57159ccd0dd2?source=rss-e0df7febb671------2</link>
            <guid isPermaLink="false">https://medium.com/p/57159ccd0dd2</guid>
            <dc:creator><![CDATA[阿伯拉底]]></dc:creator>
            <pubDate>Mon, 27 Aug 2018 07:24:22 GMT</pubDate>
            <atom:updated>2018-08-27T07:57:59.785Z</atom:updated>
            <content:encoded><![CDATA[<p>尼可拉斯凱吉沒有演氣象人續集，但我有。繼氣象人第一集獲得好評(120個claps)後，決定再向登峰造極挑戰。這次我在氣象人App新增了以下功能：</p><ol><li>文字描述氣象改成圖案描述。(目不識丁也可以使用)</li><li>增加當日最高溫與最低溫。(了解氣候就像人情有冷暖)</li><li>用星期幾代替年月日。(我們更在意今天星期幾勝於今天幾月幾日，尤其今天是否是星期五至關重要)</li></ol><p>若你沒follow第一集請看這個：</p><p><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/%E6%B0%A3%E8%B1%A1%E4%BA%BA-a021b7e526ec">氣象人</a></p><p>執行動畫如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*3Z9lbPH-2Fodozi567X00A.gif" /></figure><p>截圖如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*wvy-V2wUc-7vfzTVKc7xDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*f3PK8qhcwAJqI8yYqGHJdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*as2xkYH0YZjc0oQSQ3koMg.png" /></figure><p>GitHub如下：</p><p><a href="https://github.com/justinlin0819/WeatherMan">justinlin0819/WeatherMan</a></p><p>使用到的主要技術如下：</p><ol><li>用Decoder和Codable的方式解析JSON資料，主要程式碼如下：</li></ol><p><strong>override</strong> <strong>func</strong> viewDidLoad() {</p><p><strong>super</strong>.viewDidLoad()</p><p>label_city.text = <strong>self</strong>.city</p><p><strong>let</strong> urlStr = “http://data.taipei/opendata/datalist/apiAccess?scope=resourceAquire&amp;rid=e6831708-02b4-4ef8-98fa-4b4ce53459d9&quot;</p><p><strong>if</strong> <strong>let</strong> url = URL(string: urlStr) {</p><p><strong>let</strong> task = URLSession.shared.dataTask(with: url) { (data, response , error) <strong>in</strong></p><p><strong>let</strong> decoder = JSONDecoder()</p><p>decoder.dateDecodingStrategy = .iso8601</p><p><strong>if</strong> <strong>let</strong> data = data, <strong>let</strong> weather = <strong>try</strong>? decoder.decode(Weather.<strong>self</strong>, from: data) {</p><p>DispatchQueue.main.async {</p><p><strong>var</strong> i = 0</p><p><strong>for</strong> w <strong>in</strong> weather.result.results {</p><p><strong>if</strong> w.locationName == <strong>self</strong>.city {</p><p><strong>let</strong> weekday = Calendar.current.component(.weekday, from: w.startTime)</p><p><strong>switch</strong> weekday {</p><p><strong>case</strong> 1:</p><p><strong>self</strong>.label_date[i].text = “星期日”</p><p><strong>case</strong> 2:</p><p><strong>self</strong>.label_date[i].text = “星期一”</p><p><strong>case</strong> 3:</p><p><strong>self</strong>.label_date[i].text = “星期二”</p><p><strong>case</strong> 4:</p><p><strong>self</strong>.label_date[i].text = “星期三”</p><p><strong>case</strong> 5:</p><p><strong>self</strong>.label_date[i].text = “星期四”</p><p><strong>case</strong> 6:</p><p><strong>self</strong>.label_date[i].text = “星期五”</p><p><strong>case</strong> 7:</p><p><strong>self</strong>.label_date[i].text = “星期六”</p><p><strong>default</strong>:</p><p><strong>break</strong></p><p>}</p><p><strong>if</strong> (i &gt; 0) &amp;&amp; (<strong>self</strong>.label_date[i].text == <strong>self</strong>.label_date[i-1].text) {</p><p><strong>continue</strong></p><p>}</p><p><strong>switch</strong> w.parameterName1 {</p><p><strong>case</strong> “多雲時陰短暫陣雨或雷雨”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “多雲時陰短暫陣雨或雷雨”)</p><p><strong>case</strong> “陰時多雲短暫陣雨或雷雨”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “多雲時陰短暫陣雨或雷雨”)</p><p><strong>case</strong> “多雲時陰陣雨或雷雨”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “多雲時陰短暫陣雨或雷雨”)</p><p><strong>case</strong> “多雲短暫陣雨或雷雨”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “多雲時陰短暫陣雨或雷雨”)</p><p><strong>case</strong> “陰短暫陣雨或雷雨”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “多雲時陰短暫陣雨或雷雨”)</p><p><strong>case</strong> “陰時多雲陣雨或雷雨”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “多雲時陰短暫陣雨或雷雨”)</p><p><strong>case</strong> “多雲短暫陣雨”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “多雲時陰短暫陣雨或雷雨”)</p><p><strong>case</strong> “晴午後短暫雷陣雨”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “多雲時陰短暫陣雨或雷雨”)</p><p><strong>case</strong> “陰時多雲”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “陰時多雲”)</p><p><strong>case</strong> “陰天”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “陰時多雲”)</p><p><strong>case</strong> “晴時多雲”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “晴時多雲”)</p><p><strong>case</strong> “多雲”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “多雲”)</p><p><strong>case</strong> “陰陣雨或雷雨”:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “雷雨”)</p><p><strong>default</strong>:</p><p><strong>self</strong>.image_weather[i].image = UIImage(named: “晴”)</p><p>}</p><p><strong>self</strong>.label_temph[i].text = w.parameterName2</p><p><strong>self</strong>.label_templ[i].text = w.parameterName3</p><p>i = i + 1</p><p><strong>if</strong> i == 7 {</p><p><strong>break</strong></p><p>}</p><p>}</p><p>}</p><p>}</p><p>}</p><p>}</p><p>task.resume()</p><p>}</p><p>2. 實作TableView的cell被touch的action，主要程式碼如下：</p><p><strong>override</strong> <strong>func</strong> tableView(<strong>_</strong> tableView: UITableView, didSelectRowAt indexPath: IndexPath) {</p><p><strong>var</strong> city: String = “”</p><p><strong>switch</strong> indexPath.row {</p><p><strong>case</strong> 1:</p><p>city = “臺北市”</p><p><strong>case</strong> 2:</p><p>city = “新北市”</p><p><strong>case</strong> 3:</p><p>city = “桃園市”</p><p><strong>case</strong> 4:</p><p>city = “臺中市”</p><p><strong>case</strong> 5:</p><p>city = “臺南市”</p><p><strong>case</strong> 6:</p><p>city = “高雄市”</p><p><strong>case</strong> 7:</p><p>city = “基隆市”</p><p><strong>case</strong> 8:</p><p>city = “新竹縣”</p><p><strong>case</strong> 9:</p><p>city = “新竹市”</p><p><strong>case</strong> 10:</p><p>city = “苗栗縣”</p><p><strong>case</strong> 11:</p><p>city = “彰化縣”</p><p><strong>case</strong> 12:</p><p>city = “南投縣”</p><p><strong>case</strong> 13:</p><p>city = “雲林縣”</p><p><strong>case</strong> 14:</p><p>city = “嘉義縣”</p><p><strong>case</strong> 15:</p><p>city = “嘉義市”</p><p><strong>case</strong> 16:</p><p>city = “屏東縣”</p><p><strong>case</strong> 17:</p><p>city = “宜蘭縣”</p><p><strong>case</strong> 18:</p><p>city = “花蓮縣”</p><p><strong>case</strong> 19:</p><p>city = “臺東縣”</p><p><strong>case</strong> 20:</p><p>city = “澎湖縣”</p><p><strong>case</strong> 21:</p><p>city = “金門縣”</p><p><strong>case</strong> 22:</p><p>city = “連江縣”</p><p><strong>default</strong>:</p><p><strong>break</strong></p><p>}</p><p><strong>if</strong> <strong>let</strong> controller = storyboard?.instantiateViewController(withIdentifier: “weathertableview”) <strong>as</strong>? WeatherTableViewController {</p><p>controller.city = city</p><p>present(controller, animated: <strong>true</strong>, completion: <strong>nil</strong>)</p><p>}</p><p>}</p><p>3. 使用Dispatchmainqueue在 main thread執⾏ UI 相關的程式。</p><p>心得感想：</p><ol><li>上一集的氣象人App我並沒有實作TableView的cell被touch的action，而是直接在每個cell放了button，用button的action寫程式。所以這次實作cell被touch的action就需要把所有button移除，在每個cell重新放入Label，然後再對每個Label寫上城市名，總共22個，花了一些時間，這時發現台灣真的很大，有22個主要行政區。</li><li>看到台南市的天氣聯想到這次水災，真心為南部人，為台灣祈福。</li><li>要針對每種氣象文字描述搭配不同的圖案真的不容易，主要是因為我們的氣象文字描述實在有太多相似，很多用語看起來很像是同一個意思，結果卻分成那麼多種。舉例來說，大家知道這幾個氣象描述有什麼不同嗎？</li></ol><p>(1) 多雲時陰短暫陣雨或雷雨</p><p>(2) 陰時多雲短暫陣雨或雷雨</p><p>(3) 多雲時陰陣雨或雷雨</p><p>(4) 多雲短暫陣雨或雷雨</p><p>(5) 陰短暫陣雨或雷雨</p><p>(6) 陰時多雲陣雨或雷雨</p><p>(7) 多雲短暫陣雨</p><p>我是不懂有什麼不同，但我還是得在程式裡為每一個描述做判斷來設定圖案。</p><p>4. 今天是最後一堂課，我想就拿這個當作期末demo的App吧！本來想做梭哈、西洋棋來demo的，但那個要做到可以玩也可以demo可能要到年底吧！XD 還是來一句氣象人的電影經典名言來做結尾：Nothing that has meaning is easy. Easy doesn’t enter into grown-up life. 中文意思是：有意義的事絕不會是輕而易舉的。成人世界中，更沒有輕而易舉的事。學習設計iOS App兩個月下來，真的體會要精通這門技術且完成一個可以上架賺錢的App，真的不是輕而易舉的事啊！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*swRX7WByU8UZrlsoOKYDnw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57159ccd0dd2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E6%B0%A3%E8%B1%A1%E4%BA%BA%E7%BA%8C%E9%9B%86-57159ccd0dd2">氣象人續集</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[訂丸作食茶飲料]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E8%A8%82%E4%B8%B8%E4%BD%9C%E9%A3%9F%E8%8C%B6%E9%A3%B2%E6%96%99-b03ba83b410b?source=rss-e0df7febb671------2</link>
            <guid isPermaLink="false">https://medium.com/p/b03ba83b410b</guid>
            <dc:creator><![CDATA[阿伯拉底]]></dc:creator>
            <pubDate>Sat, 25 Aug 2018 16:21:18 GMT</pubDate>
            <atom:updated>2018-08-25T16:21:18.645Z</atom:updated>
            <content:encoded><![CDATA[<p>本以為班上會有同學寫出訂飲料的App，結果都沒有人寫，是有這麼難嗎？XD</p><p>不過我自己這個訂飲料App也是拿某學姊的來改。沒辦法，反正原理，觀念是知道，但不想自己一行一行寫，因為太花時間，當然也是不熟練啦！不過因為想趕快交稿，所以還是拿人家寫好的來改比較快。</p><p>執行畫面如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*451n_GDQknt9EJWvCEC6jQ.gif" /></figure><p>截圖如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*EZOSH0P05zLbevgeQj-tYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*hrb_MNIGiVHVxQhK40dkjg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*M-5mmc_z7LMfNxDcwAlQiA.png" /></figure><p>主要技術還是上傳資料和解析JSON，但是這個有動態產生cell，算是我第一次試用的技術。</p><p>這個App現在寫出來算是姍姍來遲，因為彼得潘已經把Google訂飲料表單拿出來了XD。還有就是我只寫了新增和檢視結果，編輯和刪除還沒完成，之後有時間再弄吧！大家眼尖的會注意這個封面和logo就是我們這次要喝的飲料店名喔！</p><p>GitHub：</p><p><a href="https://github.com/justinlin0819/Drink">justinlin0819/Drink</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b03ba83b410b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E8%A8%82%E4%B8%B8%E4%BD%9C%E9%A3%9F%E8%8C%B6%E9%A3%B2%E6%96%99-b03ba83b410b">訂丸作食茶飲料</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[氣象人]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E6%B0%A3%E8%B1%A1%E4%BA%BA-a021b7e526ec?source=rss-e0df7febb671------2</link>
            <guid isPermaLink="false">https://medium.com/p/a021b7e526ec</guid>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[阿伯拉底]]></dc:creator>
            <pubDate>Thu, 16 Aug 2018 08:26:18 GMT</pubDate>
            <atom:updated>2018-08-16T08:26:18.590Z</atom:updated>
            <content:encoded><![CDATA[<p>氣象人(The Weather Man)是一部我很喜歡的電影，由當年正紅的尼可拉斯凱吉主演，雖然尼可現在已經過氣，但當年他主演過很多好片。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*aySBLF15pOQmjh8FyZMT3w.jpeg" /></figure><p>之所以喜歡這部電影是因為它的劇情真實反映了人生很多事，以及無奈。希望大家有空可以欣賞一下，我這邊就不透露劇情，只節錄電影中最令我有感覺的一句台詞：The shit life, we must chuck somethings. We must chuck them, in the shit life. 中文意思是：在人生坎坷的旅途中，一定要有所放棄，因為人生坎坷。當時聽到這句話真的快落淚了。</p><p>閒話不多說，趕緊來介紹這個App。簡單講，你可以用這個App查詢全國22個縣市一週內的天氣。因為我利用解析JSON的方式，抓取了台北市政府關於一週氣象預測的Open Data。執行動畫如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*Iysy67njOnGhh-OHub8Pkg.gif" /></figure><p>擷取畫面如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*etKwaDJr3s7bbxSN5bGG9w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*5Vd0lr-3z2ZdPKYtBSmf_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*8zwMu3H_4ZCeMleiccY-JA.png" /></figure><p>UI沒有特別美化，因為時間實在不多，我把重點擺在功能完成上。就像氣象人電影說的，we must chuck somethings. we must chuck them…</p><p>本App用到的關鍵技術如下：</p><ol><li>解析JSON資料</li><li>用程式開啟下一個頁面以及回到首頁</li><li>用程式傳遞資料到下一個頁面</li></ol><p>關鍵程式碼在此：</p><p><strong>@IBAction</strong> <strong>func</strong> button_cityselection(<strong>_</strong> sender: UIButton) {</p><p><strong>var</strong> date = [String]()</p><p><strong>var</strong> weather = [String]()</p><p><strong>var</strong> city: String = “”</p><p><strong>switch</strong> sender {</p><p><strong>case</strong> button_city[0]:</p><p>city = “臺北市”</p><p><strong>case</strong> button_city[1]:</p><p>city = “新北市”</p><p><strong>case</strong> button_city[2]:</p><p>city = “桃園市”</p><p><strong>case</strong> button_city[3]:</p><p>city = “臺中市”</p><p><strong>case</strong> button_city[4]:</p><p>city = “臺南市”</p><p><strong>case</strong> button_city[5]:</p><p>city = “高雄市”</p><p><strong>case</strong> button_city[6]:</p><p>city = “基隆市”</p><p><strong>case</strong> button_city[7]:</p><p>city = “新竹縣”</p><p><strong>case</strong> button_city[8]:</p><p>city = “新竹市”</p><p><strong>case</strong> button_city[9]:</p><p>city = “苗栗縣”</p><p><strong>case</strong> button_city[10]:</p><p>city = “彰化縣”</p><p><strong>case</strong> button_city[11]:</p><p>city = “南投縣”</p><p><strong>case</strong> button_city[12]:</p><p>city = “雲林縣”</p><p><strong>case</strong> button_city[13]:</p><p>city = “嘉義縣”</p><p><strong>case</strong> button_city[14]:</p><p>city = “嘉義市”</p><p><strong>case</strong> button_city[15]:</p><p>city = “屏東縣”</p><p><strong>case</strong> button_city[16]:</p><p>city = “宜蘭縣”</p><p><strong>case</strong> button_city[17]:</p><p>city = “花蓮縣”</p><p><strong>case</strong> button_city[18]:</p><p>city = “臺東縣”</p><p><strong>case</strong> button_city[19]:</p><p>city = “澎湖縣”</p><p><strong>case</strong> button_city[20]:</p><p>city = “金門縣”</p><p><strong>case</strong> button_city[21]:</p><p>city = “連江縣”</p><p><strong>default</strong>:</p><p><strong>break</strong></p><p>}</p><p><strong>let</strong> urlStr = “http://data.taipei/opendata/datalist/apiAccess?scope=resourceAquire&amp;rid=e6831708-02b4-4ef8-98fa-4b4ce53459d9&quot;</p><p><strong>if</strong> <strong>let</strong> url = URL(string: urlStr) {</p><p><strong>let</strong> task = URLSession.shared.dataTask(with: url) { (data, response , error) <strong>in</strong></p><p><strong>if</strong> <strong>let</strong> data = data, <strong>let</strong> dic = <strong>try</strong>?</p><p>JSONSerialization.jsonObject(with: data) <strong>as</strong>? [String: <strong>Any</strong>], <strong>let</strong> result1 = dic?[“result”] <strong>as</strong>? [String: <strong>Any</strong>], <strong>let</strong> result2 = result1[“results”] <strong>as</strong>? [[String: <strong>Any</strong>]]{</p><p><strong>for</strong> location <strong>in</strong> result2 {</p><p><strong>let</strong> id = location[“_id”] <strong>as</strong>! String</p><p><strong>let</strong> city_t = location[“locationName”] <strong>as</strong>! String</p><p><strong>let</strong> weather_t = location[“parameterName1”] <strong>as</strong>! String</p><p><strong>let</strong> date_t = location[“startTime”] <strong>as</strong>! String</p><p><strong>if</strong> (Int(id)! % 2 == 0) &amp;&amp; city_t == city {</p><p>date.append(String(date_t.prefix(10)))</p><p>weather.append(String(weather_t))</p><p>}</p><p>}</p><p>}</p><p>}</p><p>task.resume()</p><p>}</p><p><strong>while</strong> date.count != 7 {</p><p>}</p><p><strong>if</strong> <strong>let</strong> controller = storyboard?.instantiateViewController(withIdentifier: “weathertableview”) <strong>as</strong>? WeatherTableViewController {</p><p><strong>for</strong> i <strong>in</strong> 0…6 {</p><p>controller.date.append(date[i])</p><p>controller.weather.append(weather[i])</p><p>}</p><p>present(controller, animated: <strong>true</strong>, completion: <strong>nil</strong>)</p><p>}</p><p>}</p><p>GitHub在這：</p><p><a href="https://github.com/justinlin0819/WeatherMan-master">justinlin0819/WeatherMan-master</a></p><p>這次覺得最困難的部分就是讀懂dataTask程式的寫法，光是這部分真的卡關卡很久，只能說Swift還蠻多眉角的。其實我之前就有個夢想，想寫一個App可以統合所有政府機關的Open Data，然後利用大數據的分析，從中找出一些關鍵的、有價值的資訊，這次學會了解析JSON的技術真的很開心，感謝彼得潘。大家也可以拿這個App和iPhone內建的天氣App比看看誰的比較準喔~~XD</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a021b7e526ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E6%B0%A3%E8%B1%A1%E4%BA%BA-a021b7e526ec">氣象人</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[梭哈人生第一章]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E6%A2%AD%E5%93%88%E4%BA%BA%E7%94%9F%E7%AC%AC%E4%B8%80%E7%AB%A0-99fbdfd00c96?source=rss-e0df7febb671------2</link>
            <guid isPermaLink="false">https://medium.com/p/99fbdfd00c96</guid>
            <dc:creator><![CDATA[阿伯拉底]]></dc:creator>
            <pubDate>Sun, 12 Aug 2018 15:54:08 GMT</pubDate>
            <atom:updated>2018-08-13T01:04:16.112Z</atom:updated>
            <content:encoded><![CDATA[<p>最近太多事情忙，本來想寫梭哈App的計劃一直延宕，如果要等到全部寫完再po到部落格，可能這幾週都不會有產出，所以決定將寫這個App的過程分成幾個章節，寫到什麼進度就先po個文章。</p><p>這週的進度主要是構思兩個功能：</p><ol><li>發牌</li><li>如何讓兩個玩家可以在同一台手機玩這個遊戲。</li></ol><p>第一點主要是亂數的應用，第二點比較特別。因為我希望這個App在兩個玩家之間能夠很smooth地輪流玩。何謂smooth？就是輪到某個玩家時，拿到手機看到的畫面是自己的牌在自己的面前，而且對方該蓋住的牌是蓋住的，不能打開來看，自己該蓋住的牌也是蓋住的，只有自己可以打開來看。</p><p>這裡要先請大家先看一下梭哈的遊戲規則：</p><p><a href="https://zh.wikipedia.org/wiki/%E6%A2%AD%E5%93%88">梭哈 - 维基百科，自由的百科全书</a></p><p>在進行梭哈的遊戲過程中，每個玩家一定有一張牌是蓋著，這張牌就是第一張發的牌。只有屬於這張牌的玩家自己可以看這張牌的內容，其它玩家都不能看。直到五張牌都發完，而且遊戲結束前大家決定亮牌時，才可以把這張牌打開，這張牌就是俗話說的底牌。這週的進度我簡化成一開始都先發五張牌給兩個玩家，每個玩家可以看到自己所有的牌，但只能看到另一個玩家的四張明牌，底牌看不到，輪換玩家時也是維持這樣的畫面。只是輪換玩家時，必須先點擊自己的底牌，底牌才會被打開。這樣很合理，因為如果不先蓋起來，上一個玩家就會看到下一個玩家的底牌。</p><p>這週就是先把這兩大功能寫好，接下來再思考如何完成梭哈App其它的功能。這週完成的執行結果動畫如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*oFdANQC-k0USllWE5WiXEA.gif" /></figure><p>App執行畫面截圖如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*DKmZowjRxVF6_asCKsW0AA.png" /><figcaption>剛發好牌</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*7DPOClqYdOvftwZlstvNqQ.png" /><figcaption>玩家一按下輪到玩家二後的畫面</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*7JqPKu4cwE-wSajc_0wAIw.png" /><figcaption>玩家二點擊底牌讓底牌掀開</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*InPRGg6bwQIaioV8vL1VsQ.png" /><figcaption>玩家二按輪到玩家一後的畫面</figcaption></figure><p>這個App使用到最近學的技術有以下幾個：</p><ol><li>亂數。</li><li>傳遞參數到下一個頁面。</li><li>使用append新增字串陣列</li><li>實作func viewWillAppear(_ animated: Bool)</li></ol><p>比較重要的程式碼節錄如下：</p><p><strong>var</strong> first=1</p><p><strong>override</strong> <strong>func</strong> viewDidLoad() {</p><p><strong>super</strong>.viewDidLoad()</p><p><em>// Do any additional setup after loading the view, typically from a nib.</em></p><p>cards.shuffle()</p><p>button_card.setBackgroundImage(UIImage(named: cards[0].image), for: .normal)</p><p><strong>for</strong> i <strong>in</strong> 1…9 {</p><p>image_card[i-1].image = UIImage(named: cards[i].image)</p><p>}</p><p>image_card[0].image=UIImage(named: “back”)</p><p>}</p><p><strong>override</strong> <strong>func</strong> viewWillAppear(<strong>_</strong> animated: Bool) {</p><p><strong>if</strong> first != 1 {</p><p>button_card.setBackgroundImage(UIImage(named: “back”), for: .normal)</p><p>}</p><p>}</p><p><strong>@IBAction</strong> <strong>func</strong> open_card(<strong>_</strong> sender: <strong>Any</strong>) {</p><p>button_card.setBackgroundImage(UIImage(named: cards[0].image), for: .normal)</p><p>}</p><p><strong>@IBAction</strong> <strong>func</strong> button_changeplayer(<strong>_</strong> sender: <strong>Any</strong>) {</p><p>first=0</p><p>}</p><p><strong>override</strong> <strong>func</strong> prepare(for segue: UIStoryboardSegue, sender: <strong>Any</strong>?) {</p><p><em>// Get the new view controller using segue.destination.</em></p><p><em>// Pass the selected object to the new view controller.</em></p><p><strong>let</strong> controller = segue.destination <strong>as</strong>! SwitchPlayerViewController</p><p><strong>for</strong> i <strong>in</strong> 0…9 {</p><p>controller.cards.append(<strong>self</strong>.cards[i])</p><p>}</p><p>}</p><p>GitHub連結如下：</p><p><a href="https://github.com/justinlin0819/ShowHand">justinlin0819/ShowHand</a></p><p>我自己評估接下來還有一堆功能要做，包括實現完整的梭哈遊戲過程，如下注、牌型比較、跟與不跟、籌碼計算……所以我想這個梭哈人生應該還有好幾集，下次見了。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99fbdfd00c96" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E6%A2%AD%E5%93%88%E4%BA%BA%E7%94%9F%E7%AC%AC%E4%B8%80%E7%AB%A0-99fbdfd00c96">梭哈人生第一章</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[色感測驗(iOS遊戲App)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E8%89%B2%E6%84%9F%E6%B8%AC%E9%A9%97-ios%E9%81%8A%E6%88%B2app-f7725cbecf26?source=rss-e0df7febb671------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7725cbecf26</guid>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[阿伯拉底]]></dc:creator>
            <pubDate>Wed, 01 Aug 2018 08:11:30 GMT</pubDate>
            <atom:updated>2018-08-01T08:21:11.863Z</atom:updated>
            <content:encoded><![CDATA[<p>最近接連學了調色、亂數……等技術，我就在想，是否可以結合這兩個技術寫個遊戲App？最後終於讓我想到了！就是跳脫猜數字、猜牌、問答題……等等的框架，而是猜顏色。猜顏色當然不是直接猜電腦用亂數選的顏色，而是電腦用亂數出一個顏色當題目，然後使用者利用RGB三個顏色去調合成電腦出的這個題目的顏色。因為電腦出的這個顏色一定是RGB組合而成的(本App都是把Alpha設為1)，所以一定存在RGB三個數字可以調合成，如果使用者調對了這三個數值，就算答對題目。簡言之，這個遊戲是在考使用者對顏色的敏感度，如果有修過色彩學的人應該很容易答出來，比如有些人就是知道紅色加綠色會變成黃色，像我這種沒修過而且對各種顏色的組合知識很弱的，真的是蠻困難的遊戲。老實說，我自己設計完這個App後試玩，我還沒有答對過一次XD。沒關係，誰說設計遊戲的人一定是很會玩該遊戲呢？我只要能考倒大家就行了XD。</p><p>廢話不多說，先附上執行動畫：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*Ry44FPjtvoaBlOpNkJVkWw.gif" /></figure><p>使用者開啟App後，就會看到上方是電腦出的題目，使用者就是要用下方的調色slider去調合成電腦出的那個顏色，調色結果是在作答右邊的圖。每個slider右方會顯示這個原色目前的值，範圍是0~255，需要微調可以使用stepper元件。如果認為自己調對了，就按提交，就會知道是否有答對。若真的調不出來，很想知道答案就按公布解答，左下方就會有三個數字，分別代表RGB三個數值的答案。如果要跳到下一題，可以按下一題，讓電腦重新出題。本App沒有限制作答時間，使用者可以慢慢調XD。</p><p>App截圖如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*gCavpFmW_0YDuK7WAInwog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*vJ7vR0Pp5pWFsZVPfpyUjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*Tlu-DoDUHozAcpZFv8R42Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*uBNyWO2j_K1QusHNPPgSjA.png" /></figure><p>用亂數產生顏色及設定顏色的主要程式碼如下：</p><p><strong>@IBAction</strong> <strong>func</strong> slider_ColorChange(<strong>_</strong> sender: UISlider) {</p><p>red = CGFloat(Int(slider_ColorChange[0].value))/255</p><p>green = CGFloat(Int(slider_ColorChange[1].value))/255</p><p>blue = CGFloat(Int(slider_ColorChange[2].value))/255</p><p>label_RGBValue[0].text = String(Int(slider_ColorChange[0].value))</p><p>label_RGBValue[1].text = String(Int(slider_ColorChange[1].value))</p><p>label_RGBValue[2].text = String(Int(slider_ColorChange[2].value))</p><p>stepper_ColorChange[0].value = Double(Int(slider_ColorChange[0].value))</p><p>stepper_ColorChange[1].value = Double(Int(slider_ColorChange[1].value))</p><p>stepper_ColorChange[2].value = Double(Int(slider_ColorChange[2].value))</p><p>label_Answer.backgroundColor = UIColor(red: red, green: green, blue: blue, alpha: 1)</p><p>}</p><p><strong>@IBAction</strong> <strong>func</strong> stepper_ColorChange(<strong>_</strong> sender: UIStepper) {</p><p>red = CGFloat(Int(stepper_ColorChange[0].value))/255</p><p>green = CGFloat(Int(stepper_ColorChange[1].value))/255</p><p>blue = CGFloat(Int(stepper_ColorChange[2].value))/255</p><p>label_RGBValue[0].text = String(Int(stepper_ColorChange[0].value))</p><p>label_RGBValue[1].text = String(Int(stepper_ColorChange[1].value))</p><p>label_RGBValue[2].text = String(Int(stepper_ColorChange[2].value))</p><p>slider_ColorChange[0].value = Float(Int(stepper_ColorChange[0].value))</p><p>slider_ColorChange[1].value = Float(Int(stepper_ColorChange[1].value))</p><p>slider_ColorChange[2].value = Float(Int(stepper_ColorChange[2].value))</p><p>label_Answer.backgroundColor = UIColor(red: red, green: green, blue: blue, alpha: 1)</p><p>}</p><p><strong>override</strong> <strong>func</strong> viewDidLoad() {</p><p><strong>super</strong>.viewDidLoad()</p><p><em>// Do any additional setup after loading the view, typically from a nib.</em></p><p>question_red = CGFloat(Int.random(in: 0…255))/255</p><p>question_green = CGFloat(Int.random(in: 0…255))/255</p><p>question_blue = CGFloat(Int.random(in: 0…255))/255</p><p>label_Question.backgroundColor = UIColor(red: question_red, green: question_green, blue: question_blue, alpha: 1)</p><p>label_Answer.backgroundColor = UIColor(red: 127/255, green: 127/255, blue: 127/255, alpha: 1)</p><p>label_RGBValue[0].text = “127”</p><p>label_RGBValue[1].text = “127”</p><p>label_RGBValue[2].text = “127”</p><p>stepper_ColorChange[0].value = 127</p><p>stepper_ColorChange[1].value = 127</p><p>stepper_ColorChange[2].value = 127</p><p>slider_ColorChange[0].value = 127</p><p>slider_ColorChange[1].value = 127</p><p>slider_ColorChange[2].value = 127</p><p>label_StandardAnswer.text = <strong>nil</strong></p><p>}</p><p>GitHub如下：</p><p><a href="https://github.com/justinlin0819/color_feeling_test">justinlin0819/color_feeling_test</a></p><p>對顏色敏感度低的，常會覺得RGB三個slider怎麼滑動就是沒辦法調出和題目看起來相似的顏色，即使有時滑到好像快接近了，結果答案就是不對，看了解答才知道有一兩個數值還是差很多。所以，我覺得顏色的組合其實也是蠻深奧的學問，這種藝術的問題，即使有高超的邏輯思考或數學計算能力也不一定能解決。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7725cbecf26" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E8%89%B2%E6%84%9F%E6%B8%AC%E9%A9%97-ios%E9%81%8A%E6%88%B2app-f7725cbecf26">色感測驗(iOS遊戲App)</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[棒打老虎雞吃蟲(iOS 遊戲App)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E6%A3%92%E6%89%93%E8%80%81%E8%99%8E%E9%9B%9E%E5%90%83%E8%9F%B2-ios-%E9%81%8A%E6%88%B2app-ca79a877ca1b?source=rss-e0df7febb671------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca79a877ca1b</guid>
            <dc:creator><![CDATA[阿伯拉底]]></dc:creator>
            <pubDate>Sun, 29 Jul 2018 15:29:49 GMT</pubDate>
            <atom:updated>2018-07-29T15:38:46.389Z</atom:updated>
            <content:encoded><![CDATA[<p>這個週末完成了一個遊戲App，棒打老虎雞吃蟲，這是源自於某個綜藝節目的趣味遊戲，想知道原本的遊戲規則可以參考：</p><p><a href="https://zh.wikipedia.org/wiki/%E6%A3%92%E6%89%93%E8%80%81%E8%99%8E%E9%9B%9E%E5%90%83%E8%9F%B2">棒打老虎雞吃蟲 - 维基百科，自由的百科全书</a></p><p>我是根據這個規則做了些微改變，並以卡牌遊戲的方式呈現。改變以後的規則如下：</p><ol><li>玩家和電腦各持四張牌，這四張牌分別是棒、老虎、雞、蟲各一張。</li><li>分四個回合，每回合同時出一張牌，同時亮牌。</li><li>棒子贏老虎、雞。</li><li>老虎贏雞、蟲。</li><li>雞贏蟲。</li><li>蟲贏棒子。</li><li>如果雙方同時出一樣的牌，則判定雙方平局。</li><li>贏一回合得一分，四個回合比完後總分最高者勝利。</li></ol><p>為了讓電腦的四張牌能夠以亂數的方式隨機排列出牌的順序，使用了shuffle()這個函數。也就是我先宣告一個字串陣列如下：</p><p><strong>var</strong> cards = [“棒”, “老虎”, “雞”, “蟲”]</p><p>然後在每次viewDidLoad()時執行cards.shuffle()。這樣就能確保每一盤新的遊戲開始時都是像被洗過牌似的，這樣才無法預測電腦的出牌順序。</p><p>這個App也應用了Popover，在每一盤遊戲結束時彈出Popover告訴玩家贏或輸。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*tmz9ashbQKslf686-FuecA.png" /></figure><p>遊戲執行過程動畫如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*UqnyFXvsAX8Drz7Dgco6dw.gif" /></figure><p>各個卡牌使用的圖如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/1*Dv-Lyhoj2ndR271d7_3J5A.png" /><figcaption>棒子</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/1*THzjImUaHcrXUwWwLh8BiA.png" /><figcaption>老虎</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/1*-KKBPvumyy8VPCcAIaP6Qg.png" /><figcaption>雞</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/1*VZnGIYMH_pMyLT6nkC3HSw.png" /><figcaption>蟲</figcaption></figure><p>GitHub網址：</p><p><a href="https://github.com/justinlin0819/-">justinlin0819/-</a></p><p>最後要分享的是這個遊戲看似運氣成份為主，但其實策略運用或機率計算在其中也是很重要的。比如當電腦第一張牌出了蟲，就可以確定自己的棒子接下來是獨大的，頂多遇到棒子會平局，所以接下來出棒子得分的機率是很高的。因為這個遊戲每一種牌都只有一張，出去了就沒了，這也說明了資源的有限，必須善加利用。基本上，這和戰國時代孫臏幫田忌賽馬所提出的下駟對上駟，上駟對中駟，中駟對下駟的戰術類似。這裡順便貼上田忌賽馬的典故。</p><p><a href="https://read01.com/zh-tw/Kn572L.html#.W13bFC33Wt8">https://read01.com/zh-tw/Kn572L.html#.W13bFC33Wt8</a></p><p>而會在遊戲畫面稱呼電腦為AI是因為我發現雖然電腦是以亂數、隨機的方式出牌，但要贏好像也不是那麼容易，我自己玩了很多次，勝率是不高的，這讓我彷彿感覺到AI的存在。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca79a877ca1b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E6%A3%92%E6%89%93%E8%80%81%E8%99%8E%E9%9B%9E%E5%90%83%E8%9F%B2-ios-%E9%81%8A%E6%88%B2app-ca79a877ca1b">棒打老虎雞吃蟲(iOS 遊戲App)</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[中國哲學電子書(iOS App)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E4%B8%AD%E5%9C%8B%E5%93%B2%E5%AD%B8%E9%9B%BB%E5%AD%90%E6%9B%B8-ios-app-85f7c161671b?source=rss-e0df7febb671------2</link>
            <guid isPermaLink="false">https://medium.com/p/85f7c161671b</guid>
            <dc:creator><![CDATA[阿伯拉底]]></dc:creator>
            <pubDate>Mon, 23 Jul 2018 09:08:49 GMT</pubDate>
            <atom:updated>2018-07-23T09:11:15.724Z</atom:updated>
            <content:encoded><![CDATA[<p>中華文化源遠流長，尤其春秋戰國時諸子百家的哲學經典更是瑰麗的一個篇章。把這些經典做成電子書，讓人人有經典可以閱讀一直是我的心願，畢竟人人有功練可能很難達成，人人有哲學唸倒是可行的。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*4HonAUAm175NcHgj5Ei7rQ.jpeg" /></figure><p>於是在彼得潘的指導下，不寫任何一行程式碼完成了這部曠世巨作，其畫面精美，字體大小適中，操作流暢，先來欣賞動畫圖如下(此為模擬器設置為iPhone 6所錄製)：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*z7c9A00KUK-_zppPzHiaHQ.gif" /></figure><p>因為經典實在浩如煙海，在下在有限的時間就先選定儒家、道家、兵家的經典來放入此App，之後有空再補進期他各家的經典。</p><p>另外截了幾張圖如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*EfBr0u_VXY1Tqaq2raWEqw.png" /><figcaption>精美的app icon</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*6UszfuRMN6BA8EdBPmLScA.png" /><figcaption>app的首頁</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*yV8k7Yd861mOwUfa_QJRaA.png" /><figcaption>古典捲軸式呈現各章節</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*x8QCTKiVkhqczRfDyWD6YA.png" /><figcaption>背景色調柔和</figcaption></figure><p>GitHub連結：</p><p><a href="https://github.com/justinlin0819/20180717-2">justinlin0819/20180717-2</a></p><p>這個App的主要技術都是圍繞在tab bar controller、navigation controller、table view controller的操作與設定。看似簡單，其實對初學者來說蠻多細節要注意的，例如標題、背景、顏色、各頁面顯示順序……真的是稍有不慎就會有錯誤，總之就是多練習才會多熟練。</p><p>相信大家在學生時代都有讀過論語，但有讀過孫子兵法的應該就不多，出社會尤其需要讀孫子兵法，可以讓你在職場、情場都得意，這也是我選定兵家的經典放進這個電子書的原因。希望這樣的App可以在大家對人生迷惘時點出一盞明燈。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85f7c161671b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E4%B8%AD%E5%9C%8B%E5%93%B2%E5%AD%B8%E9%9B%BB%E5%AD%90%E6%9B%B8-ios-app-85f7c161671b">中國哲學電子書(iOS App)</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[製作一頁精美的App畫面 — 美國隊長抓寶]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E8%A3%BD%E4%BD%9C%E4%B8%80%E9%A0%81%E7%B2%BE%E7%BE%8E%E7%9A%84app%E7%95%AB%E9%9D%A2-%E7%BE%8E%E5%9C%8B%E9%9A%8A%E9%95%B7%E6%8A%93%E5%AF%B6-fb8a24b22794?source=rss-e0df7febb671------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb8a24b22794</guid>
            <dc:creator><![CDATA[阿伯拉底]]></dc:creator>
            <pubDate>Mon, 16 Jul 2018 07:21:17 GMT</pubDate>
            <atom:updated>2018-07-16T07:32:20.649Z</atom:updated>
            <content:encoded><![CDATA[<p>這次要來練習的是製作一頁精美的App畫面，因為我平常喜歡抓寶貝，就是玩寶可夢，所以想到以這個為題材。我想先以目前最新版的寶可夢封面當底圖。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*30NV7OC-Dtp9SSPFcASWvw.png" /></figure><p>然後在這畫面上放上可愛的皮卡丘，方法是從寶可夢遊戲中檢查每個神奇寶貝的畫面選擇皮卡丘，會出現這張圖。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*nlPFngBW_3qH5LaDR8x0zQ.png" /></figure><p>這時用Preview沿著皮卡丘周圍剪下成一個方形的圖，存成另一個檔案，然後用Preview對這圖去背，變成這樣：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*i04c3hyCeY1rKZsZPfU0rA.png" /></figure><p>接下來男主角要登場了，我的構想是想讓玩家扮演美國隊長，畢竟小智抓那麼多年了，也該休息了。所以在網路上抓了美國隊長的圖，順便去背。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*3idazNey-i9pg08wmqDJIQ.png" /></figure><p>也許復仇者聯盟和神奇寶貝的碰撞可以產生一些新意，這留待遊戲設計商去思考XD。</p><p>然後接下來就是在Xcode中拉兩個Image View元件，分別放入美國隊長和皮卡丘，擺在適當地位置(不要互相擋到XD)，而且要表現出美國隊長在奔跑抓皮卡丘的感覺。模擬器是選擇iPhone 6(因為小弟我現在還是用iPhone 6不肯換XD)。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZEnEIO9NUBypgFtVmPw2mg.png" /></figure><p>執行後的畫面如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*cm5wDv9McHZ7vGgad48_eg.png" /></figure><p>另外，我也把寶可夢的app icon拿來使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*0A3X4re5BUzFWxJfiUsXgQ.png" /></figure><p>Gif動畫：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*6rMFWoKt5nr6nD0u-s7QUg.gif" /></figure><p>GitHub位址：</p><p><a href="https://github.com/justinlin0819/beauti_cover">justinlin0819/beauti_cover</a></p><p>當然如果玩家想選鋼鐵人或其它的，這可以在遊戲實際開發中時擴充，到時這個App的名稱可以叫做復仇者聯盟抓寶。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb8a24b22794" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E8%A3%BD%E4%BD%9C%E4%B8%80%E9%A0%81%E7%B2%BE%E7%BE%8E%E7%9A%84app%E7%95%AB%E9%9D%A2-%E7%BE%8E%E5%9C%8B%E9%9A%8A%E9%95%B7%E6%8A%93%E5%AF%B6-fb8a24b22794">製作一頁精美的App畫面 — 美國隊長抓寶</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>