<?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/@bluesky20242?source=rss-d303e5ce28c3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OQHnn4YxKVMFOIoA6ct_Fg.jpeg</url>
            <title>Stories by 黃金米 on Medium</title>
            <link>https://medium.com/@bluesky20242?source=rss-d303e5ce28c3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 17:46:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bluesky20242/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/%E5%BF%83%E7%90%86%E6%B8%AC%E9%A9%97app-5f329b4c6d32?source=rss-d303e5ce28c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f329b4c6d32</guid>
            <dc:creator><![CDATA[黃金米]]></dc:creator>
            <pubDate>Sat, 16 Apr 2022 10:50:01 GMT</pubDate>
            <atom:updated>2022-04-16T12:33:01.693Z</atom:updated>
            <content:encoded><![CDATA[<p>作業目的: 熟練資料傳遞的技巧。</p><p>首先我先在storyboard建立多個view controller跟navigation bar controller，再來設置元件。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pqR6PG1pNEKWjO0jdzywBw.png" /></figure><p>因為我有很多個view controller，所以我將主要的兩個controller重新命名，方式如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A1QyJO8nM4ROHhW2CwEiJw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uNG_OOmHsvKz0vaa33SGQw.png" /></figure><p>接著點選我要改的view controller來改。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fuHuHhrKllWOZ9yEZOQJlw.png" /></figure><p>接著，我先設定一個新的file，來定義我的題目＆選項答案的屬性（Stiring之類的）。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A1QyJO8nM4ROHhW2CwEiJw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2VX7v1tkBxFNYs_QFkkU8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ovu2gUihrPSAAhWtJs818g.png" /></figure><p>設定好後，我在點擊button選項view controller(QuestionsViewController)加入我的題庫。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IKR-nxI_P-4Z8UfrvMt_DQ.png" /></figure><p>接著我先拉我會用到的outlet。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OjexYEE1aSn0IQ0gs6Smeg.png" /></figure><p>並且宣告我會用到的function跟變數。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MLPeEodehZqhueg9gRMmFg.png" /></figure><p>接著我再來連button的IBAction，並且寫程式。</p><p>＊當使用者點擊button時，將測驗的特質加入到answerString裡面，方便最後結果使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JinJgzuuf-xzvErf65CiLA.png" /></figure><p>題目總共有四題，當index等於4的時候，使用 performSegue(withIdentifier: sender:) 換頁。</p><p>這裡大家會發現withIdentifier: “<strong>End</strong>”，這個end是哪裡來的呢？</p><p>首先，我們要先把兩個controller拉線連結，作法如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*taQAaGFX4SU9rG9XEP0MsQ.png" /></figure><p>這個拉線的名字我設定為End。</p><p>因此我在程式中的withIdentifier才會寫End。</p><p>接著，我再來拉IBSegueAction，利用它來傳送資料。</p><p>＊因為同時串連兩個頁面，<strong>一定要將拉線放在第一個controller裡來寫程式。</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EwxMhyg_Q_HYuSaEX5UIjQ.png" /></figure><p>接著，我們再去顯示結果的controller(ResultViewController)寫程式。</p><p>一樣，我先拉label的outlet，方變我後面寫程式用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NZpQbv8dIR9160M8UzaqzQ.png" /></figure><p>接著我要透過init來接收前一頁所傳的值。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JF9m2Pa7VKlOo8V5hjrAmA.png" /></figure><p>接下來，我要先寫一個function來顯示最後結果的16種性格，最後再將function放上viewDidLoad裡。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VRVww5wFCyomo9g8KhX9qw.png" /></figure><p>因為總共要寫16個，function很長，所以我只節錄部分就好。</p><p>＊字串裡如果要顯示空格可以用\n，但因為我有太多要換行的，所以我在內容的上下各加入三個「“」，這樣就可以多行空格。</p><p>以下是模擬器的操作畫面：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*JbT59MZ8TPL2MXYIai5QaQ.gif" /></figure><p>以下是參考連結：</p><ul><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/16-%E5%BF%83%E7%90%86%E6%B8%AC%E9%A9%97%E6%88%96%E5%95%8F%E5%8D%B7-app-d8910d1345e">#16 心理測驗或問卷 App</a></li><li><a href="https://womany.net/read/article/27411">16 型人格心理測驗：將你的「真實性格」以及「性格潛在問題」一網打盡｜女人迷 Womany</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/35%E5%BF%83%E7%90%86%E6%B8%AC%E9%A9%97app-d0bb34e66f3e">#36心理測驗App</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/57-%E5%BF%83%E7%90%86%E6%B8%AC%E9%A9%97-app-bf0f1381eaa9">#57 心理測驗 App</a></li><li><a href="https://www.twblogs.net/a/5cda5857bd9eee6726ca0717">swift 字符串和字符 換行</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f329b4c6d32" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%BF%83%E7%90%86%E6%B8%AC%E9%A9%97app-5f329b4c6d32">心理測驗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/%E7%8C%9C%E6%8B%B3app-5894ff95297e?source=rss-d303e5ce28c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/5894ff95297e</guid>
            <dc:creator><![CDATA[黃金米]]></dc:creator>
            <pubDate>Mon, 04 Apr 2022 06:14:37 GMT</pubDate>
            <atom:updated>2022-04-04T12:36:40.235Z</atom:updated>
            <content:encoded><![CDATA[<p>猜拳APP</p><p>這個作業是要做一個剪刀石頭布的app，首先在網路上找三種拳的圖片放進Assets。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvphO9U08yidCI6xhxreeQ.png" /></figure><p>接著在storyboard上建立我所需要的元件：image view、label、button，並且拉IBOutlet。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4pLXyQdeX2GyI5UvVvtzyg.png" /></figure><p>其中如果想要button不是顯示字而是顯示圖片，先點擊button元件，然後選擇我放進assets的圖片。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*CxcrriXRXcpFCVJTBkguYA.png" /></figure><p>接著我們先列出玩家＆電腦的出拳照片陣列。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wh2ayZUrrJYa19Hb6k3VRQ.png" /></figure><p>接著先寫出一個輸贏的Finction，因為會根據出拳不一樣有九種的條件要假設，所以程式碼會很長。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qlxwiFkVal8K2N3a8FI08A.png" /></figure><p>前置設定完之後，我這邊還要設置一個寫一段程式碼在viewDidLoad裡面，因為在一開始我沒有要讓label顯示在畫面上。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*UDfWfmOsa7E2jcHZAT8uyw.png" /></figure><p>最後就是把button拉IBAction（三個button都拉在同一個IBAction），然後打程式。</p><p>＊這裡case的scissors、rock、paper是我先前拉IBOutlet幫button outlet所取的名。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LkMaxhucmG5N7-lKuIRqzw.png" /></figure><p>以下附上模擬器操作畫面</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*DgU4K8Q3lgvg6LpxdjzSJw.gif" /></figure><p>以下是GitHub連結</p><p><a href="https://github.com/ChingMi/paper-scissors-rock">GitHub - ChingMi/paper-scissors-rock</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5894ff95297e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E7%8C%9C%E6%8B%B3app-5894ff95297e">猜拳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 — Date Picker 和 Date 的練習]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%80%92%E6%95%B8%E8%A8%88%E6%99%82app-date-picker-%E5%92%8C-date-%E7%9A%84%E7%B7%B4%E7%BF%92-1dc52379fda6?source=rss-d303e5ce28c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1dc52379fda6</guid>
            <dc:creator><![CDATA[黃金米]]></dc:creator>
            <pubDate>Sun, 27 Mar 2022 09:36:38 GMT</pubDate>
            <atom:updated>2022-03-27T14:33:58.809Z</atom:updated>
            <content:encoded><![CDATA[<h3>倒數計時APP — Date Picker 和 Date 的練習</h3><p>目的: 學習使用 Date Picker，Date 和將 Date 變成字串。</p><p><strong>在storyboard建立元件＆拉outlet（用綠色的粗線來對應outlet跟元件）</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*23s_gxHXqeh19Z9g860xvw.png" /></figure><p>這個作業並沒有做到進階的在模擬器上倒數秒數，所以在date picker上的preffered style是設定wheel、mode選擇date。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*sDHHNqrklPgYsAJM72yOww.png" /></figure><p>因為這是倒數計時器，代表用戶選擇的日期會是大於當日日期，避免用戶會選到以前的日期，所以在viewDidLoad我先設定一段程式碼(紅色框框)，讓datePicker能選擇的最小日期是今天。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cwYA2j0K9qoNWYav_pYgbg.png" /></figure><p>為了能讓用戶打上想倒數的事情，所以我拉了一個text field的IBAction（黃色框框），裡面雖然沒有程式碼，但重要的是在這我設定event是Did End On Exit，只要按go或是return就能收起鍵盤。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oZCKV5CWvqAsncNH54hIdg.png" /></figure><p><strong>date picker元件的IBAction</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iUh4sgN3hZzruttqnVUhGQ.png" /></figure><p>裡面可以看到，我分別先取出兩個日期：今天日期let now = Date()，還有用picker所選擇的日期let goal = sender.date。</p><p>接著我用interval來相減兩的日期（前提是這兩個型別都要是Date）： let interval = goal.timeIntervalSinceNow</p><p>截圖就是這個APP完整的程式碼，所以這次就不放上GitHub囉～</p><p>以下是模擬器操作畫面：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*KiFFZ18ny6PkyvkuBEMUfA.gif" /></figure><p>以下是參考的作業連結，還有模擬器沒辦法跑出鍵盤的解法：</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%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E5%96%9A%E9%86%92-ios-%E6%A8%A1%E6%93%AC%E5%99%A8%E6%B6%88%E5%A4%B1%E7%9A%84%E9%8D%B5%E7%9B%A4-a4c2f4aaf7d9">喚醒 iOS 模擬器消失的鍵盤</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/40-%E4%B8%96%E7%95%8C%E6%9C%AB%E6%97%A5%E5%80%92%E6%95%B8%E8%A8%88%E6%99%82-date-picker-%E5%92%8C-date-%E7%9A%84%E7%B7%B4%E7%BF%92-ab4d385772f">#40 倒數計時 — Date Picker 和 Date 的練習</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/the-final-countdown%E5%AD%B8%E6%B8%AC%E8%A8%88%E6%99%82%E5%99%A8-c9fe5fd160d2">The Final Countdown學測計時器</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1dc52379fda6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%80%92%E6%95%B8%E8%A8%88%E6%99%82app-date-picker-%E5%92%8C-date-%E7%9A%84%E7%B7%B4%E7%BF%92-1dc52379fda6">倒數計時APP — Date Picker 和 Date 的練習</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[領隊生活2 Year Challenge]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E9%A0%98%E9%9A%8A%E7%94%9F%E6%B4%BB2-year-challenge-ff19fe7adad3?source=rss-d303e5ce28c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff19fe7adad3</guid>
            <dc:creator><![CDATA[黃金米]]></dc:creator>
            <pubDate>Sat, 26 Mar 2022 13:40:40 GMT</pubDate>
            <atom:updated>2022-03-27T03:59:13.826Z</atom:updated>
            <content:encoded><![CDATA[<p>作業目的：</p><p>1、使用 date picker &amp; slider 做時間的魔法師。</p><p>2 、slider &amp; picker 要連動，比方 slider 滑到 2018，picker 也要顯示 2018。</p><p>3、時間自動快轉的照片輪播功能。</p><p><strong>在Assets裡面放入圖片＆命名</strong></p><p>為了後面coding時好操作，我把圖片名稱都先命名成年月日，而又由於在coding時，我用dateComponentPicker.month找到的數值，小於十月的數值都會是1、2、3….以此類推，而非01、02、03….等，所以我在命名圖片名稱時，才會打成：2018(年)1(月)01(日)。至於日我都統一設定為01是這樣方便好更換照片，例如我在程式碼中所打的：imageOutlet.image = UIImage(named: “\(year)\(month)01”)。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8FE2q4BybMYC3V2lqgzZSg.png" /></figure><p><strong>先在storyboard建立元件＆設定</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3JLLJeFODiMlFKKjIquoPg.png" /></figure><p>在date picker我們要設定的是呈現方式，例如inline就像行事曆的呈現方式，在這裡我選擇設定成wheel，也就是畫面中所呈現的樣子。</p><p>Locale則是呈現哪一個國家的年、月、日表現方式。</p><p>Date地方則是來設定你要只要呈現日期、還是日期加時間等。也可以設定最小＆最大的日期，這樣能鎖住區域範圍。像我的帶團時間是從2016年的12月到2019年。</p><p><strong>用圖片來呈現我所對應的IBOutlet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YC7VTOVX_85-f25lQm3EYg.png" /></figure><p><strong>初始畫面</strong></p><p>在一開始我想要switch是關閉的，所以我在viewDidLoad裡面寫的這段程式碼。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4lRhpU2qN0qggpiOdP32OA.png" /></figure><p><strong>datePicker的Action</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8LDM_3R7_MmfF7uGtwXLw.png" /></figure><p><strong>slider的Action</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_juR9Wz9trFFLa2KDnZSxA.png" /></figure><p><strong>自動播放照片的switch</strong></p><p>一開始我們要先宣告自動播放的年份、月份、還有重複執行任務的timer。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZCsPPsYj9JWqworL2ByGZA.png" /></figure><p>接著我們先寫出像是自動播放照片/關閉自動播放的function，方便我們待會在switch action裡面coding。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V9vzdxIIzD_zWyAP02mXPA.png" /></figure><p>前置作業結束後，我們就能來拉IBAction跟coding囉。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YmqPAV7F6u7M9_kuwTfVvw.png" /></figure><p>模擬器操作畫面如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*yJ39wZc6xs3n_SyCo2AZzw.gif" /></figure><p>以下是這個作業的GitHib</p><p><a href="https://github.com/ChingMi/yearChallenge">GitHub - ChingMi/yearChallenge</a></p><p>以下是參考的連結</p><ul><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/69-10yearchallenge-%E6%99%82%E9%96%93%E9%83%BD%E5%8E%BB%E5%93%AA%E4%BA%86-5060e3fd5459">#69 10YearChallenge，時間都去哪了</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/mamamoo-7yearchallenge-%E6%AD%B2%E6%9C%88%E5%9C%A8%E5%A5%B3%E7%A5%9E%E8%BA%AB%E4%B8%8A%E5%BE%9E%E4%BE%86%E5%B0%B1%E4%B8%8D%E6%98%AF%E6%8A%8A%E6%AE%BA%E8%B1%AC%E5%88%80-e6641d7995ab">Mamamoo 7YearChallenge ，歲月在女神身上從來就不是把殺豬刀</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff19fe7adad3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E9%A0%98%E9%9A%8A%E7%94%9F%E6%B4%BB2-year-challenge-ff19fe7adad3">領隊生活2 Year Challenge</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 的解鎖畫面(passcode)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/app-%E7%9A%84%E8%A7%A3%E9%8E%96%E7%95%AB%E9%9D%A2-passcode-36c51c5fa63e?source=rss-d303e5ce28c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/36c51c5fa63e</guid>
            <dc:creator><![CDATA[黃金米]]></dc:creator>
            <pubDate>Sun, 13 Mar 2022 10:30:10 GMT</pubDate>
            <atom:updated>2022-03-13T12:07:25.996Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*RykNsZnLmF2qdxwTunS7FA.png" /></figure><p>在畫面一開始，我先新增一些我會用到的元件。例如：註明輸入密碼的label、四位數密碼會用到的四個image view、還有數字跟刪除鍵的button。</p><p>除了底圖星空照片是從網路上下載的之外，其他都是內建的元件。</p><p>至於照片放入則是先拉一個image view拉大到跟螢幕一樣大，然後再把照片從Assets裡拉進去。</p><p>接下來這張照片是各自對應的Outlet，在這裡無論是星星image還是數字button我都是拉outlet collection。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*OG6Ij_ax3j9nL6110j0XYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sMZwnKTXSaNFkU0p2wMHeA.png" /></figure><p>拉完之後，我宣告一些我會用到的常數跟變數。<br>在這裡，因為正確密碼只會有一組，所以我是用常數來宣告，其餘都是變數。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*QUIwdYTJoss_FpSSz-WQ5Q.png" /></figure><p>各種的function：</p><p><strong>變更照片</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*IQ2Uj0NT3Gzr6atdn6Th0Q.png" /></figure><p>參考其他學長姐的程式碼，在這裡我用swtich來判斷目前點擊的次數（currentClip）是多少，再來改變我的圖片。</p><p>在這裡會看到每個case中，都是先將highlight取消，再個別判斷是否highlight，原因是按下button後，會依照currentClip的次數來highlight。</p><p>但是，以delete來說，每取消一個currentClip的次數，如果只有本來的highlight，就沒有判斷取消highlight的功能，所以先將全部取消，每次delete都能再判斷開啟多少highlight。</p><p>看到這裡大家一定會疑問hightlight到底是要幹嘛用的？這裡我們先回到storyboard的介面來看。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*3Ft14YD222zQlgbLP5tCPQ.png" /></figure><p>紅色框框是一開始我所設定的image view所顯示的圖片。而在Highlighted的欄位我選了填滿的星星圖片（上面的藍色框框），代表是能更改圖片的，但也必須注意這個圖案是不能被使用者選取的，所以interaction（下面的藍色框框）不能打勾。</p><p>在這邊設定完之後，我們再看回變更照片的程式碼：.isHighlighted = true 代表變更照片成我所設定的填滿的星星。</p><p><strong>確認密碼是否正確</strong></p><p>在這裡我先寫一個條件式：當點擊次數等於四次時，才會執行這個function。</p><p>接著，當用戶所輸入的密碼 等於 或 不等於 正確密碼時，會各自跳出一個訊息視窗。<br>＊此篇文章的最後我會放入彼得潘的訊息視窗教學連結。</p><p>對於初次寫這程式的人一定要注意，最後一句：present(allertController, animated: <strong>true</strong>, completion: reset)一定要寫，不然訊息框不會彈跳出來。</p><p>在最後一項completion，我這邊寫的是reset。原因是因為當輸入正確/錯誤密碼時，我都想讓畫面重新開始，所以我放入一個reset的function，如果大家不想要讓畫面或是程式碼有變動，那填入nil就好了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F_ZndC5ws-p2bOU6SmnSFQ.png" /></figure><p><strong>重新開始</strong></p><p>將所有數值歸零，至於變更照片沒寫在這程式裡，是因為在變更照片的function中我已經寫了最後一項default: for i in 0…3 {imagesOutlet[i].isHighlighted = false}，來讓星星圖片回歸到最一開始沒填滿的樣子。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bRtqYD1x480A4zLU4U8IRw.png" /></figure><p>function寫好後，我們來拉IBAction的outlet。</p><p><strong>點擊數字的button</strong></p><p>再拉數字button的時候，我將0~9的button全部拉進同一個IBAction裡，避免我要重複作業很多次。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*45xESAkV1DTW72ylrd2dXw.png" /></figure><p>每當點擊一次button，就先把curentClip的數值+1，然後讓function能夠正確的去跑，避免出現bug。</p><p>至於這裡看到的sender.tag則是我們在一開始設定button時就要先輸入的數值，方便程式碼在運行時，能夠自己將正確的數值代入currentNumber（用戶輸入的密碼）中。</p><p>那要怎麼設定tag呢？我們先回到button元件裡面，點擊button元件會跑出這個畫面。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*WnNlcyOqL8TATpUapXJ4KQ.png" /></figure><p>接著拉到最下面，有個tag，我們在這裡修改數值就好。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*A_u3Z8eNN8MNYen3ZKzmyw.png" /></figure><p><strong>刪除button</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T87pT0Eds3tOe-7yd2ErDg.png" /></figure><p>最後，為了讓畫面跑起來的時候，能夠讓數字button能跟iphone一樣是圓形的，所以在button時我們要來設定他的圓角度。</p><p>一樣，我們先點擊button元件，然後確認這個元件的長跟寬的數值，並且一定要是正方形，並且要選clips to bound！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*LAyI2EhfOn_lmfoFyILRzg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*MdV20JYaRNMusWrrDek4uA.png" /></figure><p>我們知道數值是100後，接著我們再到另一個頁面來設定將100/2=50，就可以變成圓角，但必須在模擬器跑動時才會看到變圓角，如果在storyboard裡還是一樣的。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*Jg7cqpxhYKgBzftFqwRPog.png" /></figure><p>模擬器操作畫面如下</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*5hNzDbmH8Ge0DOKrjzB_hA.gif" /></figure><p>此程式的GitHub網址</p><p><a href="https://github.com/ChingMi/passcode">GitHub - ChingMi/passcode</a></p><p>參考的文章</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%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E8%AE%93-view-%E8%AE%8A%E5%9C%93%E8%A7%92%E7%9A%84-layer-cornerradius-54aa7afda2a1">讓 view 變圓角的 layer.cornerRadius</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/13-xcode-app-%E7%9A%84%E8%A7%A3%E9%8E%96%E7%95%AB%E9%9D%A2-passcode-8e3df0263736">#13 Xcode — APP 的解鎖畫面(Passcode)</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/app%E8%A7%A3%E9%8E%96%E7%95%AB%E9%9D%A2-e6dbcfe100fc">APP解鎖畫面</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%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E9%A1%AF%E7%A4%BA%E8%AD%A6%E5%91%8A%E8%A8%8A%E6%81%AF%E5%92%8C%E9%81%B8%E5%96%AE%E7%9A%84-uialertcontroller-a7548b606eea">顯示警告訊息和選單的 UIAlertController</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36c51c5fa63e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/app-%E7%9A%84%E8%A7%A3%E9%8E%96%E7%95%AB%E9%9D%A2-passcode-36c51c5fa63e">App 的解鎖畫面(passcode)</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%A1%8C%E7%90%83%E8%A8%88%E5%88%86%E6%9D%BF-2dd3f8d74f91?source=rss-d303e5ce28c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2dd3f8d74f91</guid>
            <dc:creator><![CDATA[黃金米]]></dc:creator>
            <pubDate>Sat, 12 Mar 2022 10:18:08 GMT</pubDate>
            <atom:updated>2022-03-12T13:11:44.407Z</atom:updated>
            <content:encoded><![CDATA[<p>桌球規則：<br>在一局比賽中，先得11 分的一方為勝方； 10 比10 平手後，先多得2 分的一方為勝方。 通常在國際正式比賽，單項賽（單打、雙打）採用七局四勝制。</p><p>初階版我沒做到deuce後所改變的規則。</p><p>這版本主要有幾點：</p><p>一、點擊畫面時，可以增加分數。</p><p>二、當其中一方分數達到11分時，會自動歸0目前比分，並且在上方的贏局+1。</p><p>三、上方有個text field可以讓玩家自己取名，後面會連動當其中一方贏時，名字也會show上去。</p><p>四、七搶四的局面上，若其中一方贏得四局，就會跳出label顯示Win。</p><p>五、按Reset Button可以重置遊戲比分。</p><p><strong>新增元件＆拉 Outlet</strong></p><p>在一開始的storyboard，因為我想要的記分板呈現方式是橫向的，所以我在開始設定時有轉向（按紅色框框）。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uTPuxqJvk-R-ES5ZjolW2Q.png" /></figure><p>接下來畫面的線條會對應到各個元件＆outlet。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LO0goR4GMADEAf3URVfHyw.png" /></figure><p>這裡大家會發現我有兩個text field的outlet沒有標在上方。原因是因為在這個程式中，我設定可以讓玩家自由的輸入名字，因為後面贏時還要顯示玩家名稱，所以我是拉IBAction，並且特別設定只要按return就可以收起鍵盤。</p><p>為了避免使用者不知道這個框框是要幹嘛的，我有特別註解玩家1/2的名稱。<br>＊先點選元件，然後在Placeholder上寫下你想要的註解。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zsNEamRaJSQiCdl4ZjGCBQ.png" /></figure><p>為了讓鍵盤可以收起來，我在拉IBAction時，event我選擇Did End On Exit。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*xtLum9baELHcCOn7B1c2hA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1KtJbZuOJUN9DVUChLhITQ.png" /></figure><p><strong>宣告各種變數</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J9wxDlymnlh3rr3ZadHDyg.png" /></figure><p><strong>在一開始，我先把贏的label給隱藏起來。</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vD1u5KqlINvRJnj3fDUKIw.png" /></figure><p><strong>function</strong><br>方便我後面coding時，不用一直打重複的東西（在viewDidLoad外面打）。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R6TkVex3U65rXJd2fXIT0A.png" /></figure><p><strong>Tap Gesture Recognizer</strong></p><p>要設定點擊畫面就可以增加分數的方式很多，可以在元件上再加一個button來點擊觸發，或是加入tap gesture recognizer來點擊觸發。</p><p>先前的作業中我有用過Swipe gesture recognizer（從storyboard裡新增元件）。</p><p>在這次作業中，我是用程式碼打出tap gesture recognizer，程式碼如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gH6TkIyYULU8SRKV_7uqLQ.png" /></figure><p>objc func tap1Action()裡面是寫當點擊觸發時，會執行什麼程式。<br>＊如果我將兩個紅色／藍色框框擺在viewDidLoad裡，就會出現error，func必須要擺在外面。</p><p><strong>reset （重新開始）</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*j2-hgzi2bLUPkxS5_XC11A.png" /></figure><p>以下是操作模擬器的畫面＆GitHub網址。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*1CkNI5cnfiMknc5MPCtB0Q.gif" /></figure><p><a href="https://github.com/ChingMi/ScoreBoard">GitHub - ChingMi/ScoreBoard</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2dd3f8d74f91" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E6%A1%8C%E7%90%83%E8%A8%88%E5%88%86%E6%9D%BF-2dd3f8d74f91">桌球計分板</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[21點APP]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/21%E9%BB%9Eapp-3d1d099512ed?source=rss-d303e5ce28c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d1d099512ed</guid>
            <dc:creator><![CDATA[黃金米]]></dc:creator>
            <pubDate>Thu, 10 Mar 2022 10:40:22 GMT</pubDate>
            <atom:updated>2022-03-10T14:51:11.542Z</atom:updated>
            <content:encoded><![CDATA[<p>要做出的效果<br>一、跟電腦PK<br>二、可以下注籌碼</p><p>接下來，我們就來開始操作～</p><p>首先，我先在這網址找了撲克牌的牌面，並且放進Assets裡面。</p><p><a href="https://challenge.thef2e.com/works/uiux?stage=2&amp;orderBy=created_at&amp;sort=desc">The F2E - 前端 &amp; UI 修練精神時光屋</a></p><p>放進Assets裡後，為了讓在後面寫程式時，可以跑出對應的image圖片，所以我先把圖片名稱都改掉，如下圖。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1aTDL6gCezzEQtcAhc4u1g.png" /></figure><p>接著在Storyboard裡建立一些元件，例如顯示牌的image view、顯示剩餘籌碼金額的label….之類的東西。建立好之後，我們再來把它們outlet出來。</p><p>這邊要特別注意一個地方，21點的遊戲規則是在遊玩過程中，莊家跟玩家的牌最多只能出現五張牌。所以我在畫面上會放上玩家跟莊家各五個image view。但在後續寫程式碼時，為了更方便地寫程式碼，我在outlet image view的時候，先把其中一個image view設定成outlet collection，然後再把其餘四個image都拉進去，如附圖，大家就能看到我的pcCardsImage IBOutlet總共有五個image view。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*LfHtUuk_gZjevN8zsTn8-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WSriB3h_o8IyDBvrM30AYQ.png" /></figure><p>接下來這張會把所有outlet跟元件全部對應起來，讓大家方便看（雖然線條畫起來好像還是很亂）。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VhV3ZiGr4B2J2L81NzpSaw.png" /></figure><p>這邊大家能發現到黃色線條對應出的字「這裡有還沒打字的label」，這個用意是後面跑程式碼時來判斷是莊家贏還是玩家贏時，會顯示出來的label。但由於現在遊戲剛開始沒有輸贏，因此在這裡我會先把他設定隱藏起來。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JNnHMiMXLFmm02tY4ik8bw.png" /></figure><p>個人覺得先把這個大工程完成後，我們就完成三分之一了，剩下的就是如果打出程式，以及跑程式的時候有什麼問題需要修正。</p><p>接下來，一副撲克牌有四種花色，每個花色又有十三張牌，所以我們要建立出一個File來讓程式碼知道我們這些花色、牌是什麼屬性，方便我們寫程式碼。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WXC5TDCVpJyW916nf5gkIQ.png" /></figure><p>然後這個畫面我們選Swift File，再點擊next。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qfK9VHiBdrwgLLF_O8lRaQ.png" /></figure><p>這邊我們能看到，我把這個file命名為card，然後在裡面struct Card以及屬性，這邊大家會看到number，可能會覺得很奇怪，之所以我會在這邊寫這個number屬性是整數，是為了方便後面我們要讓程式碼判斷莊家跟玩家的牌點數加總起來誰大誰小，以及點數是否爆了。在這裡我設定：<br>當出現Ａ時，number會直接回傳整數11，以此類推。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*30fSoz9Vg3SiBWEt95GIjQ.png" /></figure><p>這邊做好後，我們回到程式碼頁面來宣告一些變數、常數、還有花色、牌點數的陣列、function之類的。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6gHfm-gxNUMlVGDpAbfYYA.png" /></figure><p>做到這裡，應該會有很多同學跟我一樣困惑，想說怎麼可以馬上就想到要設定這些像是剩餘籌碼金額、玩家點數、牌的數量…等東西。</p><p>像我自己在做的時候，我也是在打程式碼的時候卡住，發現我需要有變數來幫助我寫程式，我才又回過頭來宣告變數的。</p><p>如果真的想不出來就趕快求助彼得潘或是多看看其他人寫的作業程式碼，不管是哪個，一定都會對你有所幫助。</p><p>拉回正題，我們宣告完這些東西後，就開始連結各種button！</p><p><strong>加籌碼button</strong></p><p>顧名思義：點擊一次就會+50元賭金的button。<br>在這裡的程式碼很簡單，我在連IBAction時，只要點擊一次，我就能自動+50元的賭金。所以會變動的有：變數betDollars(賭金)還有現在賭金的label。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oxm8yygtsAXMGG3wMBrXRQ.png" /></figure><p><strong>開始button</strong></p><p>在設定完賭金後，按開始的按鈕會發給莊家跟玩家各兩張牌。<br>＊在for i in 0…1{ ….}裡，可以看到我在設定playerCardsImage[<strong>i</strong>].image = UIImage(named: playerCard[<strong>i</strong>].suit + playerCard[<strong>i</strong>].rank)<br>會發現[]裡面我都打i，而i之所以從0開始算是因為陣列排第一的物件，都是「第0個」。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PHGhcuLQa0-mNbjAmQf57A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4PbCy8XuEziKh3s7aH-hJg.png" /></figure><p><strong>加牌Button</strong></p><p>＊playerCard.append(cards[cardsIndex-1])<br>在[]裡大家會發現我寫cardsIndex -1，在這裡舉個例子讓大家更簡單明瞭：<br>當現在畫面中的牌數只有一張時，cardsIndex會是1，但我要呈現的imageview是一個collection，第一張照片會是第「0」個。<br>所以在這裡我才會寫cardsIndex-1。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X4iBhCt212MCzby9A9XoLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ehYMxMyxIfzPCRmc8x_RdQ.png" /></figure><p><strong>停牌button</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nAKRXmeb5eYkgPS8yraqXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*paxgqupk2jLnzJbLTn6yQw.png" /></figure><p><strong>下一局的button</strong></p><p>在下一局的button我卡關，原因有三點：</p><p>一、我的程式碼怎麼打都會死掉跑不動，後面在檢查的時候才發現因為前面我在拉IBAction時，不小心拉了兩次，所以才會造成這樣的錯誤。<br>＊要找連的IBAction有沒有多連，先點選你要找的元件（紅色框框），再按右上角的藍色框框這個東西，去查看綠色框框裡面有沒有多連結出來的IBAction。如果有多連的，就要按叉叉把它殺掉！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jCzd95wlMRrHTPRZg_IhzQ.png" /></figure><p>二、因為我要重置撲克牌照片，讓他像最一開始開啟畫面時一樣，不會有鋪克牌顯示在畫面上，所以我寫了一個重置圖片的迴圈（因為有五張照片，所以要跑五次），讓玩家跟莊家的牌image是nil。</p><p>三、在一開始我沒寫綠色框框裡的程式碼前，我只要每次跑程式，按下一局重新開始後，牌永遠都是一樣的牌。後來發現是<strong>因為我沒有先移除掉原本玩家跟莊家牌的陣列（pcCard跟playerCard）跟洗牌shuffle。</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uCoDDCiX3UM1hUlLaCCG4A.png" /></figure><p>這次21點app的點數就到這裡囉～</p><p>以下附上模擬器操作畫面＆GitHub網址～</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*fB5rubdlOVZYXfAuvCzfPQ.gif" /></figure><p><a href="https://github.com/ChingMi/21-">GitHub - ChingMi/21-</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d1d099512ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/21%E9%BB%9Eapp-3d1d099512ed">21點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[進入Swift的奇幻旅程（課程心得）]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E9%80%B2%E5%85%A5swift%E7%9A%84%E5%A5%87%E5%B9%BB%E6%97%85%E7%A8%8B-%E8%AA%B2%E7%A8%8B%E5%BF%83%E5%BE%97-8ebfccf6b1bb?source=rss-d303e5ce28c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ebfccf6b1bb</guid>
            <dc:creator><![CDATA[黃金米]]></dc:creator>
            <pubDate>Wed, 09 Feb 2022 06:51:16 GMT</pubDate>
            <atom:updated>2022-02-09T06:52:14.073Z</atom:updated>
            <content:encoded><![CDATA[<p>其實早在兩年前朋友就有極力推薦我去學Swift，但因為那時候已經有了工作，也沒想要轉換跑道，就一直把這件事情擱置在心裡。</p><p>沒想到去年疫情爆發升三級警戒，加上我人又受傷無法工作。跟朋友聊天的過程中他又重提了一次學習Swift語言的事情，我才開始上心哈哈哈！</p><p>在那期間我在網路上做功課，外加朋友推薦我報名彼得潘的課程，發現彼得潘報名網頁真的很吸引人：成為一輩子的朋友、可以實體教室上課或是線上教學，甚至可以無限次數的看。</p><p>沒有猶豫多久，我興沖沖跑去買台MAC筆電就報名彼得潘的文組班＋進階班了。</p><p>一開始上課時，讓我比較害怕的原因是我是文組的學生，怕沒辦法跟上大家的進度。還好彼得潘在上課的時候都會注意我們是不是有不懂的地方，也會立即解答。有些程式觀念對我這種初學者會比較吃力的，他都會用最簡單的方式讓我們去理解，然後再讓我們去實作。如果有人聽不懂，他會再用另外一種方式來解釋，而且也不會有以前讀書時有些老師會有的那種「恨鐵不成鋼」的表情跟語氣，一切都很NICE。而且課程中還會時不時的講一些笑話來消除我們的睡意，活絡氣氛。</p><p>每堂課上完之後，都會有一拖拉庫的作業等著你做。但彼得潘說到目前為止還沒有人完全做完過哈哈哈！大家可想而知到底作業量有多少XD</p><p>雖然沒有硬性規定大家一定要做完多少，但我還都是自覺性的有做。因為我平日還是個上班族，所以我都是用休假時間來做作業。讓我很感動的是如果我在做作業的過程中有問題，問彼得潘都可以很快的得到解答。</p><p>雖然現在文組班的課程已經上完了，但在銜接進階班課程的這段時間我還是有持續在做之前沒做完的作業。如果我有問題要問，他還是跟往常一樣很認真的回答我們問題，沒有那種課程已經結束我跟你就沒有關係的感覺。</p><p>如果因為有事當天沒辦法上課，事後都還會有錄影檔可以看。作業雖多，但做完會讓你有成就感，就算你卡住不會做，彼得潘還能讓你一直問！</p><p>像我這種數學能力弱、邏輯又不怎麼好的文組學生，在彼得班的課程中還是存活好好的，想轉換跑道或是想學程式的朋友們，真心推薦你們來報名彼得潘的課程！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ebfccf6b1bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E9%80%B2%E5%85%A5swift%E7%9A%84%E5%A5%87%E5%B9%BB%E6%97%85%E7%A8%8B-%E8%AA%B2%E7%A8%8B%E5%BF%83%E5%BE%97-8ebfccf6b1bb">進入Swift的奇幻旅程（課程心得）</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/%E9%81%B8%E6%93%87%E9%A1%8C-app-ff3b1fb8d1b3?source=rss-d303e5ce28c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff3b1fb8d1b3</guid>
            <dc:creator><![CDATA[黃金米]]></dc:creator>
            <pubDate>Sun, 06 Feb 2022 09:51:15 GMT</pubDate>
            <atom:updated>2022-02-06T14:58:02.503Z</atom:updated>
            <content:encoded><![CDATA[<p>作業目的: 學習變數，for &amp; while 迴圈，if else ，array，類別和物件，亂數，自訂資料型別，viewDidLoad，outlet &amp; action。</p><h3>基本功能</h3><ul><li>製作選擇題 App，每題有四個選項。</li><li>答對一題加 10 分 。</li><li>畫面上顯示目前題目是第幾題。</li><li>自訂資料型別。</li><li>題庫有 n 題，隨機出其中的 10 題，每次玩的時候題目順序都不一樣。( n &gt; 10 )</li><li>玩完後可選擇再玩一次，重新開始玩。</li><li>同一頁顯示問題跟分數。</li></ul><p>首先，我們先在專案裡新增一個新的file，並且建構我們的題庫。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KvdCZ4ujUBZtV6gyXF893w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TLA9DYYIYco8KELxn5bumw.png" /></figure><p>這裡要特別注意的是，在答案選項所設定的option是array，因為我要做很多個button來讓使用者選擇答案。</p><p>接著我們來建制storyboard上我們想呈現的label、跟button，並且outlet出來。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTxf8NTBig7JCejlmqagKQ.png" /></figure><p>這裡要特別注意的是：button outlet出來的時候，我因為要同時把四個選項button放在同一個IBOutlet裡，所以在一開始設定Connection時，我要選擇Outlet Collection才可以。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*uBFkwm8UOLN1kYZmDU9GbQ.png" /></figure><p>建制完label的IBOutlet後，我們先來設置題目。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4-7fLd9FvmV5nAAig2LwFg.png" /></figure><p>＊在Q&amp;A的作業當中，我是先在Controller裡宣告<strong>var</strong> questions = [Question]()，然後在viewDidLoad裡面新增。<br>這兩種做法都可以，因為我懶得一直重複.append所以就這樣打了。</p><p>定義function。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErMMWGI3peK9r7hwLUyOVg.png" /></figure><p>接著拉IBAction來寫程式碼。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CopGWnNznYfn9gcS6TJ4rw.png" /></figure><p>為了讓畫面在一開始就呈現出題目，我在viewDidLoad裡面寫程式。又因為我的題庫超過十題，因此我用shuffle的方式讓程式隨機跑出十道題目。</p><p>以下是程式執行時的螢幕錄製。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*lF2IcJSdYotD8Je29v6THQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff3b1fb8d1b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E9%81%B8%E6%93%87%E9%A1%8C-app-ff3b1fb8d1b3">選擇題 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[利用 page control，segmented control，button & gesture 更換內容]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%88%A9%E7%94%A8-page-control-segmented-control-button-gesture-%E6%9B%B4%E6%8F%9B%E5%85%A7%E5%AE%B9-f3b7cf3c918?source=rss-d303e5ce28c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3b7cf3c918</guid>
            <dc:creator><![CDATA[黃金米]]></dc:creator>
            <pubDate>Sun, 16 Jan 2022 09:13:45 GMT</pubDate>
            <atom:updated>2022-01-16T13:39:26.724Z</atom:updated>
            <content:encoded><![CDATA[<p>目的：使用 array 儲存資料內容，不須使用到 if else。</p><p>首先我們要先建立元件，然後再outlet。</p><p>接著，我們先定義會用到的array，像是電影介紹、照片等。<br>＊照片必須先導入assets裡，array裡面的照片名稱要跟assets裡的一樣。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SCZ1hi17U1PALefcftaDvg.png" /></figure><p>完成之後，我們開始將page control，segmented control，button &amp; gesture …開始outlet出來寫程式。</p><p>outlet出來後我們為了節省一直輸入重複的程式碼，我們可以先在viewDidLoad()下方寫一個func，而這個func的功用在於切換時能夠一次換掉所有要更換的元件。</p><p>我們先宣告一個變數currentPage，再來寫func。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mgZRYbcpHugwEMpzEzbfag.png" /></figure><p>這邊我們能看到func裡面有出現很多的currentPage，就是我們剛才所宣告的變數currentPage。</p><p>我們透過這個變數的更改，連動的一起更改我們的照片、簡介…等。</p><p>在宣告變數為0的用意是因為：array、segmented control ….等東西，他們的第一樣東西都是「0」，所以我才這樣宣告的。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3-t2C3xv91u0n4nTOya-gQ.png" /></figure><p>這邊結束後，我們就可以回到button元件…等去作業。</p><p>由於剛才我們已經定義過func，在各元件的程式中，我只要呼叫change()的func就好，我們的畫面就會變得很乾淨哈哈哈！！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DNlAjYr8PMj_Bcf5oq12Yw.png" /></figure><p>接著，我想要加入Swipe Gesture Recognizer (左右滑手勢），那麼我要先去想要左滑右滑就能變更的元件去做處理。</p><p>在這個作業中我想用照片來滑動，那麼我就必須先去imageView元件裡做個調整，我們要勾選「User interaction Enabled」。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DxTzbVFDH2hthZCPq-4N9w.png" /></figure><p>接著我們新增二個 Swipe Gesture 元件，並且把一個設為左滑，另一個則是右滑。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*17abpmSm1r3FdWFQxOCSaA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VlAma0g9c1UDg5vJME5xqw.png" /></figure><p>接著我們再把兩個Swipe Gesture Recognizer 給outlet出來，並且連結到同一個IBAction。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*YFCmI5vrDBHV9Hm8Etak8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ABncmFYGEISeA4mSkxvDDg.png" /></figure><p>搭拉～作業就完成囉！！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*6kQeYXoeeAnrFY9SPyE32g.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3b7cf3c918" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%88%A9%E7%94%A8-page-control-segmented-control-button-gesture-%E6%9B%B4%E6%8F%9B%E5%85%A7%E5%AE%B9-f3b7cf3c918">利用 page control，segmented control，button &amp; gesture 更換內容</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>