<?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 Yuwen Chiu on Medium]]></title>
        <description><![CDATA[Stories by Yuwen Chiu on Medium]]></description>
        <link>https://medium.com/@yuwenwenchiu?source=rss-7c45ce91e4d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*im7jbDMwlgzcRbAPbJYzlA@2x.jpeg</url>
            <title>Stories by Yuwen Chiu on Medium</title>
            <link>https://medium.com/@yuwenwenchiu?source=rss-7c45ce91e4d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 01:04:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yuwenwenchiu/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[Flutter#1 定義 function，印出讓自己一秒落淚的情歌歌詞]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/flutter-1-%E5%AE%9A%E7%BE%A9-function-%E5%8D%B0%E5%87%BA%E8%AE%93%E8%87%AA%E5%B7%B1%E4%B8%80%E7%A7%92%E8%90%BD%E6%B7%9A%E7%9A%84%E6%83%85%E6%AD%8C%E6%AD%8C%E8%A9%9E-b2429b142d47?source=rss-7c45ce91e4d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2429b142d47</guid>
            <dc:creator><![CDATA[Yuwen Chiu]]></dc:creator>
            <pubDate>Thu, 25 Jul 2024 08:30:19 GMT</pubDate>
            <atom:updated>2024-07-25T14:08:50.874Z</atom:updated>
            <content:encoded><![CDATA[<p><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/%E5%AE%9A%E7%BE%A9-function-%E5%8D%B0%E5%87%BA%E8%AE%93%E8%87%AA%E5%B7%B1%E4%B8%80%E7%A7%92%E8%90%BD%E6%B7%9A%E7%9A%84%E6%83%85%E6%AD%8C%E6%AD%8C%E8%A9%9E-851ff4147fda">#64 定義 function，印出讓自己一秒落淚的情歌歌詞</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FTxXIfcRt1WQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DTxXIfcRt1WQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FTxXIfcRt1WQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e5c0d6aaebbc5976a7d948a29334959/href">https://medium.com/media/9e5c0d6aaebbc5976a7d948a29334959/href</a></iframe><p>完整歌詞：</p><pre>作詞：徐佳瑩     作曲：徐佳瑩<br><br>倔強的表情 就這樣隔離了我們想觸摸的臉龐 不再體貼退讓<br>沉默的對話 就這樣取代了我們想聆聽的願望 不再交換悲傷<br>太自以為的世界<br>被你離開的反作用力 鎖進黑暗陷阱<br><br>一樣的月光 怎麼看得我越來越心慌<br>你留下最清楚的步伐 竟是指引我孤單的方向<br>一樣的月光 怎麼照不亮未來的形狀<br>喔 就這樣吧 我的愛 讓寂寞的月光佔據我的窗<br><br>自由的路況 就這樣阻擋了我們想超速的逃亡 不再戒慎緊張<br>獨處的時光 就這樣取代了我們想搜集的擁抱 不再殷切需要<br>太多理智的世界<br>被你離開的反作用力 鎖進黑暗陷阱<br><br>一樣的月光 怎麼看得我越來越心慌<br>你留下最清楚的步伐 竟是指引我孤單的方向<br>一樣的月光 怎麼照不亮未來的形狀<br>喔 就這樣吧 我的愛 讓寂寞的月光佔據我的窗<br><br>一樣的月光 其實看得我越來越心慌<br>怎麼你留下最真實的回憶 都是提醒我失去的聲音<br>一樣的月光 已經照不亮未來的形狀<br>喔 能回來嗎 我的愛 讓瘋狂的愛情佔據我的窗</pre><pre>void firstVerse() {<br>  print(&#39;倔強的表情 就這樣隔離了我們想觸摸的臉龐 不再體貼退讓&#39;);<br>  print(&#39;沉默的對話 就這樣取代了我們想聆聽的願望 不再交換悲傷&#39;);<br>  print(&#39;太自以為的世界&#39;);<br>}<br><br>void bridge() {<br>  print(&#39;被你離開的反作用力 鎖進黑暗陷阱&#39;);<br>}<br><br>void chorus() {<br>  print(&#39;一樣的月光 怎麼看得我越來越心慌&#39;);<br>  print(&#39;你留下最清楚的步伐 竟是指引我孤單的方向&#39;);<br>  print(&#39;一樣的月光 怎麼照不亮未來的形狀&#39;);<br>  print(&#39;喔 就這樣吧 我的愛 讓寂寞的月光佔據我的窗&#39;);<br>}<br><br>void secondVerse() {<br>  print(&#39;自由的路況 就這樣阻擋了我們想超速的逃亡 不再戒慎緊張&#39;);<br>  print(&#39;獨處的時光 就這樣取代了我們想搜集的擁抱 不再殷切需要&#39;);<br>  print(&#39;太多理智的世界&#39;);<br>}<br><br>void outro() {<br>  print(&#39;一樣的月光 其實看得我越來越心慌&#39;);<br>  print(&#39;怎麼你留下最真實的回憶 都是提醒我失去的聲音&#39;);<br>  print(&#39;一樣的月光 已經照不亮未來的形狀&#39;);<br>  print(&#39;喔 能回來嗎 我的愛 讓瘋狂的愛情佔據我的窗&#39;);<br>}</pre><p>過渡橋段bridge()和副歌chorus()都有重複，所以可以再利用～</p><pre>void main() {<br>  firstVerse();<br>  bridge();<br>  chorus();<br>  secondVerse();<br>  bridge();<br>  chorus();<br>  outro();<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jCas251MzZi5kUBEc14ytA.png" /></figure><p><a href="https://github.com/yuwenwenchiu/flutter_homework_1.git">yuwenwenchiu/flutter_homework_1</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2429b142d47" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/flutter-1-%E5%AE%9A%E7%BE%A9-function-%E5%8D%B0%E5%87%BA%E8%AE%93%E8%87%AA%E5%B7%B1%E4%B8%80%E7%A7%92%E8%90%BD%E6%B7%9A%E7%9A%84%E6%83%85%E6%AD%8C%E6%AD%8C%E8%A9%9E-b2429b142d47">Flutter#1 定義 function，印出讓自己一秒落淚的情歌歌詞</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。ExpandableButton展開式按鈕]]></title>
            <link>https://medium.com/swift-%E9%9A%A8%E7%AD%86/swift-expandablebutton%E5%B1%95%E9%96%8B%E5%BC%8F%E6%8C%89%E9%88%95-806d247dcd46?source=rss-7c45ce91e4d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/806d247dcd46</guid>
            <category><![CDATA[webview]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[tools]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[expandablebutton]]></category>
            <dc:creator><![CDATA[Yuwen Chiu]]></dc:creator>
            <pubDate>Sat, 04 Jul 2020 15:54:26 GMT</pubDate>
            <atom:updated>2020-07-04T15:54:26.156Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*DOdna7AF1vIWtBTOIX63tA.png" /></figure><p>不知不覺已經很久沒發文了🙇🏻‍♀️今天打起精神來分享一個小功能 “展開式按鈕”，之前工作上有製作需求所以就研究了一下，在這邊記錄下來也方便自己未來可以參考，如果有興趣就一起看下去吧🥳</p><p>開始之前先梳理一下展開式按鈕需要什麼效果。</p><blockquote><em>● 有一顆 ControlButton，點擊後展開其他 ToolButton，再點一次就收合<br>● 展開、收合時，ControlButton 顯示不同圖片或文字<br>● 展開、收合時，ToolButton 都要有動畫<br>● 展開時背景反灰；收合時背景還原<br>● 每個 ToolButton 都有自己的功能</em></blockquote><p>因為我想把展開式按鈕當成一個工具包來使用，所以把相關內容都包在一個 View 裡面，不只方便 Reuse 程式碼看起來也簡潔許多，使用時不容易混亂更容易維護。那我們就開始吧💪🏻💪🏻💪🏻</p><pre><strong>使用情境 { </strong>WebView側邊有一顆ControlButton，點擊後展開ToolButton。<strong> }</strong></pre><blockquote><strong><em>1. 新增繼承 UIView 的 CocoaTouchClass</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T1FzhfcExQyApCqm-vLaDw.png" /></figure><blockquote><strong><em>2. 定義相關 Property</em></strong></blockquote><p>isExpanded用來判斷目前狀態是展開或收合。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d455b5cd74b61f3f0faefc4fa616186/href">https://medium.com/media/0d455b5cd74b61f3f0faefc4fa616186/href</a></iframe><blockquote><strong><em>3. 設計 func setupShadowView()</em></strong></blockquote><p>反灰的背景 View 預設 alpha = 0 也就是完全透明，當按鈕展開時才會顯示顏色。這邊加上一個 TapGesture，當按鈕展開時點擊背景等同於點擊 ControlButton 會收合按鈕。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e81ec0708d9101ac4252456468b83a4a/href">https://medium.com/media/e81ec0708d9101ac4252456468b83a4a/href</a></iframe><blockquote><strong><em>4. 設計 func setupButtons(buttonTitles: [String])</em></strong></blockquote><p>我用簡單的 buttonTitles: [String] 傳入 func 來決定要有幾顆 ToolButton，也可以使用自訂型別讓傳入的值帶更多資料，例如：</p><pre><strong>public class</strong> ButtonInfo {<br>    <br>    <strong>var</strong> title: String!<br>    <strong>var</strong> imURL: String!<br>    <strong>var</strong> link: String!<br>    <br>    <strong>convenience init</strong>(title: String, imURL: String, link: String) {<br>        <strong>self</strong>.init()<br>        <strong>self</strong>.title = title<br>        <strong>self</strong>.imURL = imURL<br>        <strong>self</strong>.link = link<br>    }<br>}</pre><pre><strong>func</strong> setupButtons(buttonList: [ButtonInfo])</pre><p>可以依照自己的功能需求調整囉！</p><p>ToolButton 和 ControlButton 在這邊都是設定起始位置，也就是收合狀態的位置，展開狀態的位置會在點擊 ControlButton 事件處理。起始位置要在哪裡也可以自行變化唷～</p><p>設定 tag 值的用意是用來判斷 ToolButton 的順序，後面會再提到。</p><p>另外想提一個小事情，ControlButton 在 ToolButton 後面才 add 是因為我想讓 ToolButton 看起來是從 ControlButton 後面長出來而不是正面。一開始我寫相反視覺效果就怪怪的😂</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c58e1d507b4ee00efe557c2dcde63a7/href">https://medium.com/media/5c58e1d507b4ee00efe557c2dcde63a7/href</a></iframe><blockquote><strong><em>5. 設計 func setButtonStyle(button: UIButton)</em></strong></blockquote><p>所有按鈕我都想刻成圓形而且有陰影，用這個 func 設定方便 reuse。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fdc6e08e53231f1ee68bd57731362f5/href">https://medium.com/media/8fdc6e08e53231f1ee68bd57731362f5/href</a></iframe><blockquote><strong><em>6. 定義 onTouchControlButton 點擊事件</em></strong></blockquote><p>首先最重要的 isExpanded 狀態要改變，預設為 false 第一次點擊變成 true，之後每次點擊都會反轉，方便用來判斷其他元件目前要顯示什麼。</p><p>第一個變化的是 ShadowView，展開時有顏色；收合時為透明。</p><p>第二個變化的是 ToolButtons，展開時往上長；收合時回起點。ToolButton 的 y 座標 -100 是減掉 ControlButton 的位置，再依照先前存的 tag 值按順序乘上距離展開。</p><p>第三個變化的是 ControlButton，展開和收合時分別顯示不同的文字、顏色、背景。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09c45339264bbb4ff91d614024501f1d/href">https://medium.com/media/09c45339264bbb4ff91d614024501f1d/href</a></iframe><blockquote><strong><em>7. 定義 onTouchToolButton 點擊事件</em></strong></blockquote><p>點擊 ToolButton 時也需要改變反灰背景和收合按鈕，所以等同於點擊 ControlButton。</p><p>接著透過 delegate 將點擊的按鈕資訊回傳到使用 ExpandableButtonView 工具的 ViewController，這裡只簡單地用回傳 String 來示意，可以像上面提過的用自訂型別讓這個工具更靈活。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e67f9d85fcb1c54b590c8ecf95b1279/href">https://medium.com/media/8e67f9d85fcb1c54b590c8ecf95b1279/href</a></iframe><blockquote><strong><em>8. 定義傳遞資料的 delegate</em></strong></blockquote><p>之前我寫過一篇關於 delegate 的文章，不過當時還沒有認知到 ARC 和 MemoryLeak，所以相對不那麼安全，現在開始用安全的寫法吧！其實只要在 protocol 後面加關鍵字 class，就可以將 delegate 變成弱型別，另外要注意 weak property 一定要是 optional 唷！</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11174228f9755a9d14ac3ccac0137049/href">https://medium.com/media/11174228f9755a9d14ac3ccac0137049/href</a></iframe><p>參考資源：</p><p><a href="https://www.natashatherobot.com/ios-weak-delegates-swift/">iOS: How To Make Weak Delegates In Swift</a></p><blockquote><strong><em>9. 在 ViewController 使用 ExpandableButtonView</em></strong></blockquote><p>ExpandableButtonView 設定好後，記得把 delegate 指向 ViewController，然後 ViewController 要遵從 ExpandableButtonViewDelegate 並實作 func。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89c6833cc420bbe18a0ba858b9ae437c/href">https://medium.com/media/89c6833cc420bbe18a0ba858b9ae437c/href</a></iframe><blockquote><strong><em>10. 關鍵的 override func hitTest</em></strong></blockquote><p>以上 9 個步驟寫完 Run 起來看很正常，但 ViewController 的 WebView 完全無法滑動，因為被 ExpandableButtonView 的 ShadowView 擋住了！所以在 ExpandableButtonView 要多寫一個 override func hitTest，控制哪一個 View 可以被點選。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96f75a423eb6e69e2a2e238e9a57c79e/href">https://medium.com/media/96f75a423eb6e69e2a2e238e9a57c79e/href</a></iframe><p>參考資源：</p><p><a href="https://medium.com/@nguyenminhphuc/how-to-pass-ui-events-through-views-in-ios-c1be9ab1626b">How to pass UI events through views in iOS</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*vxvLYnKzlnQPGCsWQjnwsQ.gif" /></figure><p>這次的 ExpandableButtonView 工具包就先告一段落啦！之後可能會陸續記錄一些我寫過的小工具，希望我不會偷懶🥴以上如果有任何錯誤或是建議歡迎大家留言給我～</p><p>有興趣可以取用我的檔案🙆🏻‍♀️</p><p><a href="https://github.com/yuwenwenchiu/ExpabdableButton">yuwenwenchiu/ExpabdableButton</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=806d247dcd46" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift-%E9%9A%A8%E7%AD%86/swift-expandablebutton%E5%B1%95%E9%96%8B%E5%BC%8F%E6%8C%89%E9%88%95-806d247dcd46">Swift。ExpandableButton展開式按鈕</a> was originally published in <a href="https://medium.com/swift-%E9%9A%A8%E7%AD%86">Swift。隨筆</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift。Protocol＆Delegate隨筆]]></title>
            <link>https://medium.com/swift-%E9%9A%A8%E7%AD%86/swift-protocol-delegate%E9%9A%A8%E7%AD%86-21cb3b6032af?source=rss-7c45ce91e4d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/21cb3b6032af</guid>
            <category><![CDATA[delegate]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[protocol]]></category>
            <dc:creator><![CDATA[Yuwen Chiu]]></dc:creator>
            <pubDate>Mon, 27 Jan 2020 13:00:34 GMT</pubDate>
            <atom:updated>2020-01-27T13:38:29.832Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TfAH5g6d4HGRx9KxEiRu8g.jpeg" /></figure><p>上一篇文章之後我就開始準備履歷和面試，最後很幸運的拿到了Offer也開始上班了！所以我的“心願記帳APP”可能會暫時(永遠？🤣)停更，等之後更穩定有餘裕時再繼續😳</p><p>上班將近一個月以來，我深刻感受到工作的實作和過去寫的程式完全是…天差地遠🤯很多觀念都處在一種“好像懂又好像不懂”的窘境，所以我想督促自己把這些模稜兩可的地方寫成文章，藉此讓自己複習和加深印象，但但但！我的內容不一定是最正確的，如果有任何錯誤歡迎大家留言給我🙏🏻今天就從Protocol＆Delegate開始吧💪🏻</p><blockquote><strong><em>Protocol是什麼？Delegate又是什麼？</em></strong></blockquote><p>我會說Protocol是委託書，列了許多委託項目但沒有詳細內容，如果接受這份委託書就要把項目的內容列清楚並完成。也就是說，Protocol只宣告Function但沒有實作，如果遵從Protocol就要實作所宣告的Function。</p><p>Delegate是一種委託、代理的機制，它就像一個業務員，當客戶有問題時會委託業務員去處理。以TableView來說，使用Table時不知道要呈現什麼資訊，會委託DataSource和Delegate去找答案，得到答案才能建立成功。</p><p>通常用於Delegate機制的Protocol命名習慣會以Delegate為結尾。</p><blockquote><strong><em>不同物件之間的溝通方式</em></strong></blockquote><p>實際開發時，我們常常會在兩個物件之間傳遞資料和溝通，Delegate就是其中一種方式。當A物件需要接收B物件的資料來呈現畫面，或是通知B物件來回應A物件的動作時，就會替A物件宣告Protocol使用Delegate機制。我覺得簡單的解釋：A物件的某些職責委託B物件來完成＝B物件代理A物件完成某些職責；A物件的動作通知B物件來回應＝B物件回應A物件的動作。</p><p>❯❯❯ TableView(A)的DataSource和Delegate都指向了ViewController(B)，TableView(A)需要從ViewController(B)接收幾個Section、幾個Row的資料才能如願呈現在畫面上。</p><pre><strong><em>TableView(A)</em></strong>獲取資料的職責委託<strong><em>ViewController(B)</em></strong>來完成＝<strong><em>ViewController(B)</em></strong>代理了<strong><em>TableView(A)</em></strong>獲取資料的職責。</pre><p>❯❯❯ 修改資料頁(A)的修改動作通知會員資料頁(B)來回應，所以替修改資料頁(A)宣告Protocol，修改資料頁(A)的修改結果傳遞給會員資料頁(B)之後，會員資料頁(B)會顯示相應的資料。</p><pre><strong><em>修改資料頁(A)</em></strong>的修改動作通知<strong><em>會員資料頁(B)</em></strong>顯示相應資料來回應＝<strong><em>會員資料頁(B)</em></strong>顯示相應資料回應<strong><em>修改資料頁(A)</em></strong>的修改動作。</pre><blockquote><strong><em>寫個程式來舉例</em></strong></blockquote><p>以上面所說的修改會員資料例子來練習。操作流程是從<strong>會員資料頁(B)</strong>進入<strong>修改資料頁(A)</strong>，<strong>修改資料頁(A)</strong>的結果再回傳給<strong>會員資料頁(B)</strong>，所以我將Delegate通知事件的特性理解為反向傳遞時使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*zTRr7mAutKGLDkAquVCoGg.png" /></figure><p>【 從<strong>文字</strong>來看實作的 6 步驟 】</p><ol><li>宣告A物件的Protocol // EditViewController.swift</li><li>宣告A物件的Property Delegate // EditViewController.swift</li><li>通知Delegate回應A物件的事件，執行Protocol所宣告的Function // EditViewController.swift</li><li>B物件遵從A物件的Protocol // UserInfoViewController.swift</li><li>B物件實作A物件的Protocol // UserInfoViewController.swift</li><li>B物件設為A物件的代理人 // UserInfoViewController.swift</li></ol><p>【 從<strong>程式</strong>來看實作的 6 步驟 】</p><p>A物件：EditViewController.swift</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a90c78e495c3ff08e160cc89c56a3ee5/href">https://medium.com/media/a90c78e495c3ff08e160cc89c56a3ee5/href</a></iframe><p>B物件：UserInfoViewController.swift</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af83d94829f0e903729aa112ab821819/href">https://medium.com/media/af83d94829f0e903729aa112ab821819/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*_PUl5OPM3t2TV9y9gsCx9w.gif" /></figure><p>這次的Protocol＆Delegate隨筆就先告一段落啦！雖然文章篇幅不算長，但我花了滿多時間才完成，除了當作自己的學習筆記，也希望可以幫助正在閱讀的你🤘🏻以上如果有任何錯誤或是建議歡迎大家留言給我～</p><p>有興趣可以取用我的檔案🙆🏻‍♀️</p><p><a href="https://github.com/yuwenwenchiu/PracticeDelegate">yuwenwenchiu/PracticeDelegate</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21cb3b6032af" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift-%E9%9A%A8%E7%AD%86/swift-protocol-delegate%E9%9A%A8%E7%AD%86-21cb3b6032af">Swift。Protocol＆Delegate隨筆</a> was originally published in <a href="https://medium.com/swift-%E9%9A%A8%E7%AD%86">Swift。隨筆</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#Task：Part.06–近期帳務，CoreData讀取和刪除、NSFetchedResultsController監控資料]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/task-part-06-%E8%BF%91%E6%9C%9F%E5%B8%B3%E5%8B%99-coredata%E8%AE%80%E5%8F%96%E5%92%8C%E5%88%AA%E9%99%A4-nsfetchedresultscontroller%E7%9B%A3%E6%8E%A7%E8%B3%87%E6%96%99-2f5b0b69e0e5?source=rss-7c45ce91e4d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f5b0b69e0e5</guid>
            <category><![CDATA[trailingswipeactions]]></category>
            <category><![CDATA[fetchedresultscontroller]]></category>
            <category><![CDATA[core-data]]></category>
            <dc:creator><![CDATA[Yuwen Chiu]]></dc:creator>
            <pubDate>Sun, 24 Nov 2019 15:06:16 GMT</pubDate>
            <atom:updated>2019-11-24T15:17:48.019Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pY4D5rsXTeDO6_61HTwwuQ.png" /></figure><p>各位觀眾！目前讓我卡關最久的大魔王終於被我KO啦🎉其實一開始我很快就完成了從CoreData讀取資料顯示在TableView，但為了達到以日期為Section的顯示方式…我繞了很多遠路而且死了很多腦細胞🤯最後才發現，原來我少實作了一個NSFetchedResultsControllerDelegate的Function，只要加上短短幾行程式碼就能拯救我的APP🤪</p><p>這篇文章我會紀錄近期帳務的製作，包含如何從CoreData讀取和刪除資料、NSFetchedResultsController如何監控資料並回傳變更到TableView，如果有興趣就一起看下去吧！至於帳務的CoreData實體建立和儲蓄心願的步驟一樣，只是屬性相較之下比較多，可以參考<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/task-part-05-%E5%84%B2%E8%93%84%E5%BF%83%E9%A1%98%E7%B7%A8%E5%88%97-coredata%E5%84%B2%E5%AD%98-fe6dfde19e93">#Task：Part.05–儲蓄心願編列，CoreData儲存</a>。</p><blockquote><strong><em>遵從UITableView Protocol；註冊HeaderView、Cell</em></strong></blockquote><p>由於這個頁面不是直接使用UITableViewController，一開始要記得遵從UITableViewDataSource、UITableViewDelegate，並實作相關的Function。而HeaderView和Cell在最初設計Storyboard時，我分別建立了Xib來製作，所以在RecentAccountingViewController要使用就必須先註冊，才能在後續程式碼得到匹配的實體。</p><p>關於TableView我使用到的Function如下：</p><p>DataSource ➟處理資料，將所有要顯示在畫面上的資料傳過去。<br>numberOfSections、numberOfRowsInSection、cellForRowAt、</p><p>Delegate ➟處理介面，將所有對於畫面上的操作反映回系統。<br>heightForRowAt、heightForHeaderInSection、viewForHeaderInSection、trailingSwipeActionsConfigurationForRowAt</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2f578132d67fd797948e422017a6c32/href">https://medium.com/media/f2f578132d67fd797948e422017a6c32/href</a></iframe><ul><li><a href="https://developer.apple.com/documentation/uikit/uitableviewdatasource">UITableViewDataSource | Apple Developer Documentation</a></li><li><a href="https://developer.apple.com/documentation/uikit/uitableviewdelegate">UITableViewDelegate | Apple Developer Documentation</a></li></ul><blockquote><strong><em>使用NSFetchedResultsController</em></strong></blockquote><p>NSFetchedResultsController用來監控CoreData變動後所回傳的結果，並提供資料給TableView。使用前需要先匯入CoreData框架，還要遵從NSFetchedResultsControllerDelegate並指定委派來監控資料變化。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62201b469a3752903787803b84b6b47f/href">https://medium.com/media/62201b469a3752903787803b84b6b47f/href</a></iframe><p><a href="https://developer.apple.com/documentation/coredata/nsfetchedresultscontroller">NSFetchedResultsController | Apple Developer Documentation</a></p><blockquote><strong><em>讀取資料</em></strong></blockquote><p>建立一個變數存放從CoreData讀取出來的資料，在viewDidLoad讀取資料。整個流程為：從RecordMO取得NSFetchRequest物件➟使用NSSortDescriptor指定物件間的排序➟透過AppDelegate取得資料➟建立ManagedObjectContext➟初始化fetchResultController➟指定委派監控資料變化➟呼叫performFetch()執行讀取結果➟存取fetchedObjects屬性取得RecordMO物件。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef20b7f1d32269136fa8b3d9d381ce2a/href">https://medium.com/media/ef20b7f1d32269136fa8b3d9d381ce2a/href</a></iframe><blockquote><strong><em>實作UITableViewDateSource、UITableViewDelegate</em></strong></blockquote><p>現在的資料都是從資料庫獲得，TableView也依據這些資料來顯示畫面。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ba0ed020c0b17cee243224f39de09f0/href">https://medium.com/media/0ba0ed020c0b17cee243224f39de09f0/href</a></iframe><blockquote><strong><em>刪除資料</em></strong></blockquote><p>刪除資料的做法很簡單，一樣要透過AppDelegate取得資料再建立ManagedObjectContext，最後使用ManagedObjectContext的delete方法，要刪除的資料位置就是目前的indexPath，呼叫saveContext()儲存更變。刪除的動作我寫在trailingSwipeActionsConfigurationForRowAt，程式碼可以參考上面一段。</p><blockquote><strong><em>實作NSFetchedResultsControllerDelegate</em></strong></blockquote><p>如果有任何的內容更變，NSFetchedResultsControllerDelegate的Function會自動被呼叫。我在這裡實作了四個方法，一開始卡很久就是因為少做了其中的didChange sectionInfo，導致資料更變時TableView找不到正確的位置😩繞了非常多遠路修改程式卻還是有問題，最後才找到真正的病根！只要實作didChange sectionInfo就解決啦👌🏻</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51c62a3e010c9c81639a6d3f7a4ac6c0/href">https://medium.com/media/51c62a3e010c9c81639a6d3f7a4ac6c0/href</a></iframe><p><a href="https://developer.apple.com/documentation/coredata/nsfetchedresultscontrollerdelegate">NSFetchedResultsControllerDelegate</a></p><p>=====</p><p>大功告成！這篇文章我盡量寫得簡單卻完整，一方面複習製作過程，一方面當成學習筆記。雖然我的作品走到現在進度有點慢…但所有功能我都很努力去了解、克服才完成，就算繞遠路也是一種學習💪🏻</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*oTCr7OXzUfbKL7dNtuB7jg.gif" /></figure><p>如果有什麼建議歡迎留言～有興趣可以取用我的檔案🙆🏻‍♀️</p><p><a href="https://github.com/yuwenwenchiu/Task">yuwenwenchiu/Task</a></p><p>心願記帳Part.06到這邊結束，我會努力的🙇🏻‍♀️🙇🏻‍♀️🙇🏻‍♀️</p><p><strong><em>未完待續，敬請期待…</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f5b0b69e0e5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/task-part-06-%E8%BF%91%E6%9C%9F%E5%B8%B3%E5%8B%99-coredata%E8%AE%80%E5%8F%96%E5%92%8C%E5%88%AA%E9%99%A4-nsfetchedresultscontroller%E7%9B%A3%E6%8E%A7%E8%B3%87%E6%96%99-2f5b0b69e0e5">#Task：Part.06–近期帳務，CoreData讀取和刪除、NSFetchedResultsController監控資料</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[#Task：Part.05–儲蓄心願編列，CoreData儲存]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/task-part-05-%E5%84%B2%E8%93%84%E5%BF%83%E9%A1%98%E7%B7%A8%E5%88%97-coredata%E5%84%B2%E5%AD%98-fe6dfde19e93?source=rss-7c45ce91e4d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe6dfde19e93</guid>
            <category><![CDATA[core-data]]></category>
            <category><![CDATA[datecomponent]]></category>
            <category><![CDATA[persistentcontainer]]></category>
            <dc:creator><![CDATA[Yuwen Chiu]]></dc:creator>
            <pubDate>Thu, 14 Nov 2019 12:42:39 GMT</pubDate>
            <atom:updated>2019-11-14T12:42:39.802Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ChbDIQZS9_CcPE0F7n04wg.png" /></figure><p>本來預計要先把“近期帳務”完成，但要以每天日期為一個Section顯示在列表時，CoreData讀取遇到了一些困難，目前想不到方法解決😅所以我先來製作和“新增帳務”功能類似的“儲蓄心願編列”。</p><p>透過Segue傳值、輸入心願金額、輸入心願名目、選擇日期的做法可以參考<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/task-part-03-%E6%96%B0%E5%A2%9E%E5%B8%B3%E5%8B%99-%E9%BB%9E%E6%93%8Acell%E5%B1%95%E9%96%8B%E9%A1%AF%E7%A4%BApicker-14a42fb0d73e"><strong>#Task：Part.03–新增帳務，點擊Cell展開顯示Picker</strong></a>，其他部分會在以下記錄是如何完成，如果有興趣就一起看下去吧！</p><blockquote><strong><em>每月應存金額</em></strong></blockquote><p>這個欄位是依據目標金額、日期差距而得，由於日期預設為當天沒有差距，所以一開始輸入時每月應存金額等於目標金額，一但調整達成日期就會隨著日期差距計算出每月應存金額。</p><p>日期差距可以透過Calendar的dateComponents取得，[.day]會自動算出起始日和截止日的天數，所以最後我用 目標金額 / 日期差距 * 31 計算出每月應存金額。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/730337604328e0648e1dece107fe4605/href">https://medium.com/media/730337604328e0648e1dece107fe4605/href</a></iframe><blockquote><strong><em>每月儲蓄進度提醒</em></strong></blockquote><p>尚未製作…預計會用UserNotifications來完成。</p><blockquote><strong><em>建立實體Entity、屬性Attributes</em></strong></blockquote><p>使用CoreData前，需要建立實體和實體的屬性。以下圖為例，實體是Budget，而Budget擁有date、money、name三個屬性，不過屬性的部分在做後續其他功能時可能會有調整。</p><p>Entity建立完成之後需要一個Class與它對應存取CoreData，把Codegen設為Class Definition就會自動產生這個類別，但在專案導覽器不會顯示出來，程式使用時可以用右鍵Jump to Definition查看。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bl9BW0aHiXv_X3rAGYOv7A.png" /></figure><blockquote><strong><em>儲存</em></strong></blockquote><p>在CoreData中儲存資料需要三個步驟：1.建立實體的物件、2.把物件內容設為PersistentContainer的ViewContext並設定屬性、3.呼叫saveContext()方法將資料存進資料庫。</p><p>最後我加了儲存後返回上一頁的效果。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d4e31b625f0445c945c7d90ce869b52/href">https://medium.com/media/3d4e31b625f0445c945c7d90ce869b52/href</a></iframe><p>=====</p><p>大功告成！“儲蓄心願編列”的所有欄位也都可以正常輸入了，除了每月儲蓄進度提醒🥺。下一篇會紀錄“歷史儲蓄心願”是如何從CoreData中讀取資料，不過還沒製作完整…上帝保佑我🙏🏻🙏🏻🙏🏻</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*cPR4S6z5bBqb2ctXSgYznA.gif" /></figure><p>如果有什麼建議歡迎留言～有興趣可以取用我的檔案🙆🏻‍♀️</p><p><a href="https://github.com/yuwenwenchiu/Task">yuwenwenchiu/Task</a></p><p>心願記帳Part.05到這邊結束，我會努力的🙇🏻‍♀️🙇🏻‍♀️🙇🏻‍♀️</p><p><strong><em>未完待續，敬請期待…</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe6dfde19e93" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/task-part-05-%E5%84%B2%E8%93%84%E5%BF%83%E9%A1%98%E7%B7%A8%E5%88%97-coredata%E5%84%B2%E5%AD%98-fe6dfde19e93">#Task：Part.05–儲蓄心願編列，CoreData儲存</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[#Task：Part.04–新增帳務，搜尋附近地點]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/task-part-04-%E6%96%B0%E5%A2%9E%E5%B8%B3%E5%8B%99-%E6%90%9C%E5%B0%8B%E9%99%84%E8%BF%91%E5%9C%B0%E9%BB%9E-94c9edc661b1?source=rss-7c45ce91e4d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/94c9edc661b1</guid>
            <category><![CDATA[sdk]]></category>
            <category><![CDATA[mapkit]]></category>
            <category><![CDATA[core-location]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[delegate]]></category>
            <dc:creator><![CDATA[Yuwen Chiu]]></dc:creator>
            <pubDate>Mon, 04 Nov 2019 13:27:18 GMT</pubDate>
            <atom:updated>2019-11-04T15:08:29.380Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yuab2oAPZskqILQ06gzPKQ.png" /></figure><p>掌聲鼓勵👏🏻👏🏻👏🏻搜尋附近地點的功能出爐啦～首先說明一下這部分的功能：1.取得使用者位置、2.搜尋使用者附近地點、3.透過TableView顯示地點、4.輸入關鍵字過濾附近地點、5.選擇地點回傳名稱至前一頁。</p><p>我是使用Swift SDK(MapKit、CoreLocation)完成並沒有額外串接第三方API，所以功能比較簡單也有一些限制。以下會紀錄我是如何製作，如果有興趣就一起看下去吧！</p><blockquote><strong><em>取得使用者位置</em></strong></blockquote><p>定位的準備工作要先匯入CoreLocation、建立LocationManager偵測使用者位置變化、遵從CLLocationManagerDelegate，接著設定LocationManager的委任對象為目前的ViewController。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d7795ca06553235d57a7e1c8dbc4b38/href">https://medium.com/media/3d7795ca06553235d57a7e1c8dbc4b38/href</a></iframe><p>使用者位置授權也需要在Info.plist加上鍵才能正常使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EWnv2hXYiIeYilE-5SFI7w.png" /></figure><p>準備完成後，實作CLLocationManagerDelegate的didUpdateLocations方法來取得使用者位置，取得使用者位置後就可以透過MKLocalSearchRequest和 MKLocalSearch取得附近地標景點，下段說明。</p><blockquote><strong><em>搜尋使用者附近地點</em></strong></blockquote><p>這個部分需要先匯入MapKit、建立LocalSearchRequest實作LocalSearch來搜尋。LocalSearchRequest可以搭配naturalLanguageQuery用自然語言的方式帶入參數來指定搜尋準則，例如store、hotel、coffee…而place為所有類型。LocalSearch呼叫start(completionHandler:)方法開始搜尋，搜尋完成後會回傳一個MKMapItem的Array但只會有10筆資料，所以我以心願記帳APP有可能的帳務地點類型寫成一個陣列，再利用迴圈把每一個關鍵字得到的資料放入同一個陣列作為搜尋結果。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1297c03d3d215ab5a7a9f16070f485a/href">https://medium.com/media/f1297c03d3d215ab5a7a9f16070f485a/href</a></iframe><blockquote><strong><em>透過TableView顯示地點</em></strong></blockquote><p>TableView必備雙寶！遵從UITableViewDelegate、UITableViewDataSource並實作裡面的方法。這邊想要提出來的紀錄部分是，我只想在Table顯示地點名稱和地點地址，地點名稱用searchResults[indexPath.row].name獲得，但地點地址則是在searchResults[indexPath.row].placemark.title，其實把結果印出來就可以很快找到想要的資料，但我還是在這裡卡了一下😂</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae7735a3747d480cf43da5b1797214a9/href">https://medium.com/media/ae7735a3747d480cf43da5b1797214a9/href</a></iframe><p>在didSelectRowAt中透過delegate將地點名稱傳至前一頁，後面會說明。</p><blockquote><strong><em>輸入關鍵字過濾附近地點</em></strong></blockquote><p>之所以用“過濾”而不是“搜尋”是因為，這邊利用前面獲得的使用者附近地點中取得和關鍵字匹配的資料，而不是真正地可以搜尋地點，若使用者輸入不在附近地點之中的關鍵字將得不到任何結果。</p><p>輸入關鍵字的元件是SearchBar，必須遵從UISearchBarDelegate並實作textDidChange方法。當關鍵字為空時，會顯示所有使用者附近地點；當關鍵字有值時，會從使用者附近地點找出匹配的資料。</p><p>關於SearchBar還有實作另外兩個方法：searchBarSearchButtonClicked、searchBarCancelButtonClicked。SearchButton隱藏鍵盤；CancelButton清空SearchBar的文字並顯示回所有使用者附近地點。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d7ecb1c2d7808ac8fc58b8fb2c50090/href">https://medium.com/media/9d7ecb1c2d7808ac8fc58b8fb2c50090/href</a></iframe><blockquote><strong><em>選擇地點回傳名稱至前一頁</em></strong></blockquote><p>這是我第一次練習用delegate傳資料！簡單來說，在傳遞資料的Class定義Protocol並宣告要執行的Function，然後在獲得資料的Class遵從Protocol並實作Function。詳細步驟可參考彼得潘的說明，如下。</p><p><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/%E5%88%A9%E7%94%A8-delegate-%E5%9C%A8-controller-%E9%96%93%E6%BA%9D%E9%80%9A-%E5%82%B3%E8%B3%87%E6%96%99%E7%9A%84%E6%AD%A5%E9%A9%9F%E8%AA%AA%E6%98%8E-b9bc608b5e45">#78 利用 delegate 在 controller 間溝通 &amp; 傳資料的步驟說明</a></p><p>=====</p><p>大功告成！什麼功能先完成都是不可預計的呢🤪原本還說要放後面一點研究…但什麼感覺來就先做什麼吧～雖然只用Swift SDK來處理這部分不是那麼完美和完整，不過就算是用簡單的方法來實作也花了很多時間呢🥺</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*A5RPksiiJRNHNJAA-0dCgA.gif" /></figure><p>如果有什麼建議歡迎留言～有興趣可以取用我的檔案🙆🏻‍♀️</p><p><a href="https://github.com/yuwenwenchiu/Task">yuwenwenchiu/Task</a></p><p>心願記帳Part.04到這邊結束，我會努力的🙇🏻‍♀️🙇🏻‍♀️🙇🏻‍♀️</p><p><strong><em>未完待續，敬請期待…</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94c9edc661b1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/task-part-04-%E6%96%B0%E5%A2%9E%E5%B8%B3%E5%8B%99-%E6%90%9C%E5%B0%8B%E9%99%84%E8%BF%91%E5%9C%B0%E9%BB%9E-94c9edc661b1">#Task：Part.04–新增帳務，搜尋附近地點</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[#Task：Part.03–新增帳務，點擊Cell展開顯示Picker]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/task-part-03-%E6%96%B0%E5%A2%9E%E5%B8%B3%E5%8B%99-%E9%BB%9E%E6%93%8Acell%E5%B1%95%E9%96%8B%E9%A1%AF%E7%A4%BApicker-14a42fb0d73e?source=rss-7c45ce91e4d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/14a42fb0d73e</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[segmentedcontrol]]></category>
            <category><![CDATA[button-images]]></category>
            <category><![CDATA[pickerview]]></category>
            <category><![CDATA[textfield]]></category>
            <dc:creator><![CDATA[Yuwen Chiu]]></dc:creator>
            <pubDate>Mon, 28 Oct 2019 13:57:40 GMT</pubDate>
            <atom:updated>2019-11-18T05:48:49.793Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BUBpq0oYu0tQNH2uJb7MRw.png" /></figure><p>介面初步完成後馬上就進入到程式的部分！我首先進行的是“新增帳務”。</p><p>這個頁面有兩處我花比較多時間。1.切換支出或收入時下方的類別和方式依據選項而顯示不同的內容。2.日期、方式、類別的輸入方式為點擊Cell後展開Picker提供使用者選擇。</p><p>這篇文章就來記錄一下我是怎麼完成上述兩點以及其他欄位，如果有興趣就一起看下去吧！不過搜尋附近地點、發票掃描目前還沒動工😅，之後研究好再更新上來。</p><blockquote><strong><em>透過Segue傳值</em></strong></blockquote><p>由於我在設計Storyboard時，這個頁面的做法有用到ContainerView嵌入TableViewController，所以全部的欄位被拆成兩個Class控制，需要透過Segue傳值做到切換支出或收入時下方顯示不同的內容。</p><p>設定Segue識別碼為“moreInfo”以便後續程式利用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JpqPQ1_gaFml2OY-dCgJsQ.png" /></figure><p>在AddAccountingViewController.swift加入以下程式做傳值的準備。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1c035f427bd5e36d87e174b20dc2ffb/href">https://medium.com/media/c1c035f427bd5e36d87e174b20dc2ffb/href</a></iframe><blockquote><strong><em>切換支出、收入</em></strong></blockquote><p>切換功能使用SegmentedControl來製作，所以透過selectedSegmentIndex(0為支出、1為收入)來判斷，原本Cell的文字和點擊後展開的方式和類別Picker都需要顯示相應的資料。切換時把selectedSegmentIndex存入AddAccountingTableViewController的eiType，還要把方式和類別Picker的dataSource指向AddAccountingTableViewController，這樣才能如願以償地顯示正確的資料😂。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f66de34822a1bf5fa9537552c8dca3ae/href">https://medium.com/media/f66de34822a1bf5fa9537552c8dca3ae/href</a></iframe><blockquote><strong><em>加入圖片</em></strong></blockquote><p>圖片的部分使用UIImagePickerController來製作，點選照片圖示的按鈕後會彈出一個動作選單給使用者選擇，透過不同的sourceType由照片庫或者照相機來加入圖片。所在的Class也必須遵從UIImagePickerControllerDelegate和UINavigationController才能得知使用者選取的照片，再將選取的照片設定給按鈕顯示出來。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e7163c4e18a266105046a525fbe6cd1/href">https://medium.com/media/0e7163c4e18a266105046a525fbe6cd1/href</a></iframe><p>除此之外，需要在Info.plist加上兩個鍵才能正常使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TLX1A8c9Rk8XEwZT9v_Qag.png" /></figure><blockquote><strong><em>輸入金額</em></strong></blockquote><p>這個TextField的KeyboardType我設定為NumberPad，不過目前還沒有針對輸入的數字做限制判斷，例如第一個數字不能為0，預計之後會更新。另外還有實作點擊畫面其他處就隱藏鍵盤的功能。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17bf093dce4859be531229dc2f9e85cb/href">https://medium.com/media/17bf093dce4859be531229dc2f9e85cb/href</a></iframe><blockquote><strong><em>選擇日期、方式、類別</em></strong></blockquote><p>日期使用DatePicker來製作，格式設為“yyyy-MM-dd”，顯示日期的Cell預設為當天。方式、類別使用PickerView來製作，顯示方式、類別的Cell預設為陣列的第一筆資料，目前使用假資料操作。這三個Cell點選後都會展開下面一個包含Picker的Cell供使用者選擇，再次點選顯示文字的Cell時會收合包含Picker的Cell。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18d3fba07b2771d230ccdf89b128cee9/href">https://medium.com/media/18d3fba07b2771d230ccdf89b128cee9/href</a></iframe><blockquote><strong><em>輸入備註、地點</em></strong></blockquote><p>備註和地點都是TextField，這邊連結@IBAction時Event欄位要選擇DidEndOnExit，如此一來不需額外的程式碼就可以做到按下return隱藏鍵盤的功能。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zB8ED4iH1tyUf8Kh4TkPPw.png" /></figure><blockquote><strong><em>搜尋附近地點</em></strong></blockquote><p>尚未製作…</p><blockquote><strong><em>發票掃描</em></strong></blockquote><p>尚未製作…</p><p>=====</p><p>大功告成！目前所有欄位基本上都可以正常輸入，搜尋附近地點、發票掃描應該會放比較後面才研究處理，接下來目標是要設定CoreData讓使用者輸入的資料可以顯示在其他頁面。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*C7TYQV0CoibdVbsQ0CFwhw.gif" /></figure><p>如果有什麼建議歡迎留言～有興趣可以取用我的檔案🙆🏻‍♀️</p><p><a href="https://github.com/yuwenwenchiu/Task">yuwenwenchiu/Task</a></p><p>心願記帳Part.03到這邊結束，我會努力的🙇🏻‍♀️🙇🏻‍♀️🙇🏻‍♀️</p><p><strong><em>未完待續，敬請期待…</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14a42fb0d73e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/task-part-03-%E6%96%B0%E5%A2%9E%E5%B8%B3%E5%8B%99-%E9%BB%9E%E6%93%8Acell%E5%B1%95%E9%96%8B%E9%A1%AF%E7%A4%BApicker-14a42fb0d73e">#Task：Part.03–新增帳務，點擊Cell展開顯示Picker</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[#Task：Part.02–心願記帳Storyboard初版]]></title>
            <link>https://medium.com/@yuwenwenchiu/task-part-02-%E5%BF%83%E9%A1%98%E8%A8%98%E5%B8%B3storyboard%E5%88%9D%E7%89%88-c0a9d04484e?source=rss-7c45ce91e4d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0a9d04484e</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[storyboard]]></category>
            <dc:creator><![CDATA[Yuwen Chiu]]></dc:creator>
            <pubDate>Wed, 09 Oct 2019 18:21:43 GMT</pubDate>
            <atom:updated>2019-10-09T18:23:14.011Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7_eH7f78Wp7fVMP5y_WDOQ.jpeg" /></figure><p>製作畫面是我過去練習專案永遠的第一步，所以我的個人作品也從製作畫面開始！不過這當然不會是最後的模樣，先把基本的畫面架構拉出來也能暫時滿足一下自己迫切的心？🤪</p><p>在拉介面的同時我也先把對應的Class建立起來，一氣呵成才不怕後面亂套😅做著做著畫面跟檔案就變成首圖看到的那麼多了…我先用MVC將檔案稍微分類之後可能再調整，也會研究一下Storyboard References來方便管理。</p><p>接下來我會每個畫面簡單說明，如果有興趣就一起看下去吧！基本上都有先設定AutoLayout了，但還沒實際檢查在每一個裝置上是否都能正常顯示，總之這個是“初版”！😆</p><blockquote><strong><em>總覽</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*iFNxLAfQ6iosCQEMOb0v6A.png" /></figure><p>總覽頁在企劃的時候預計會有三個圖表，一個是儲蓄進度的進度條，一個是支出類別的原餅圖，一個是支出方式的原餅圖。但我現在還沒安裝任何套件…也還沒頭緒那部分該怎麼做，所以只先把文字Label放上，還有右上連結到新增帳務頁的BarButtonItem。</p><blockquote><strong><em>新增帳務</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*C2GgvLryTmdpWrAHv3cKtA.png" /></figure><p>從總覽頁到新增帳務頁是用由下往上推的Present Modally。NavigationBar有兩個BarButtonItem分別是取消和儲存，點選後都會自動收合頁面。SegmentedControl可以切換支出、收入，下方顯示對應的內容。接下來讓使用者輸入資訊的部分ImageView和TextField是在原本的View裡面，下方則是用ContainerView嵌入TableViewController，因為輸入的欄位是固定的，我想用StaticCells來完成。</p><blockquote><strong><em>近期帳務</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*nny6XI9ZcwpGjoPA8ZD5GQ.png" /></figure><p>近期帳務頁是用TableView完成，Cell顯示使用者最近的輸入的每一筆帳務資訊，SectionHeader顯示以日為單位的小計資訊。Cell和SectionHeader我都是建立Xib設計也有對應的Class，我想後續寫程式的時候也許會比較清楚。</p><blockquote><strong><em>相關設定</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*06cHZDzqPI6MpP97UQFxFQ.png" /></figure><p>相關設定頁也是列數固定的情況，所以用TabelViewController搭配StaticCells。</p><blockquote><strong><em>儲蓄心願編列</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*i-4QIhvPgAM1PcRVc2zqsQ.png" /></figure><p>儲蓄心願編列頁和新增帳務頁的作法一樣，讓使用者輸入資訊的TextField是在原本的View裡面，下方用ContainerView嵌入TableViewController搭配StaticCells來完成。</p><blockquote><strong><em>歷史儲蓄心願</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*rlDAGaomKfYpkMB5xoT2dg.png" /></figure><p>歷史儲蓄心願頁是用TableView完成，Cell顯示使用者設定的儲蓄心願資訊。</p><blockquote><strong><em>收支類別管理</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*qBTYguFx0nFhI0x1VB4zBw.png" /></figure><p>收支類別管理頁有SegmentedControl可以切換支出、收入，下方顯示對應的內容。NavigationBar有新增類別的BarButtonItem，點選後彈出AlertController。</p><blockquote><strong><em>收支方式管理</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*iKinqaLWMJNx-XPoZsZQgg.png" /></figure><p>收支方式管理頁和收支類別管理頁作法相同。</p><blockquote><strong><em>關於心願記帳</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*YQcQqARJ5ZsNq3kfV29Itw.png" /></figure><p>關於心願記帳頁很單純只用TextView完成，預計會放APP的使用介紹文字。</p><blockquote><strong><em>每月報告</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*g6d4b9jZP-mZn4ymLJlckQ.png" /></figure><p>每月報告頁會先讓使用者選擇檢視的月份，下方的內容分成兩個區塊。總收入、總支出、結餘的區塊是用ContainerView嵌入TableViewController搭配StaticCells。收入和支出的類別排行用TableView，也有使用SectionHeader來劃分兩個部分。</p><blockquote><strong><em>個人資料</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*L9nxbvVs_2xLQgazPnFmtw.png" /></figure><p>個人資料頁也很單純，預計顯示使用者圖片、使用者名稱和登入方式。</p><p>=====</p><p>大功告成！雖然看起來頁面都算單純，但我足足花了兩天半才完成！不過還是給自己鼓掌一下👏🏻以上大部分的頁面都是透過TableView完成，目前算是把基本的架構拉出來，未來可能會有變動再陸續更新～</p><p>本來有錄一個GIF但檔案太大傳不上來😭</p><p>如果有什麼建議歡迎留言～有興趣可以取用我的檔案🙆🏻‍♀️</p><p><a href="https://github.com/yuwenwenchiu/Task">yuwenwenchiu/Task</a></p><p>心願記帳Part.02到這邊結束，我會努力的🙇🏻‍♀️🙇🏻‍♀️🙇🏻‍♀️</p><p><strong><em>未完待續，敬請期待…</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0a9d04484e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#Task：Part.01–我到底要做什麼APP？]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/task-part-01-%E6%88%91%E5%88%B0%E5%BA%95%E8%A6%81%E5%81%9A%E4%BB%80%E9%BA%BCapp-1e1cadc4c716?source=rss-7c45ce91e4d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e1cadc4c716</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[prototype]]></category>
            <dc:creator><![CDATA[Yuwen Chiu]]></dc:creator>
            <pubDate>Fri, 04 Oct 2019 17:29:05 GMT</pubDate>
            <atom:updated>2019-10-07T13:45:38.284Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*7OOrgtSD9C6VCGTWnUZbEg.jpeg" /></figure><p>「萬事起頭難，開始就成功一半。」、「只要夠想要，就一定做得到！」、「佈滿荊棘的路，一步一步總能走完。」在一開始我必須對自己信心喊話一番，做個人作品這條路一定會花許多時間，也一定會碰到許多困難，我希望自己能保有熱忱和信心去完成它，就算有什麼阻礙也要提醒自己目標在哪裡，不要輕易放棄！💪🏻💪🏻💪🏻</p><blockquote><strong><em>我到底要做什麼APP？</em></strong></blockquote><p>相信每個學iOS APP開發的人，心中多少都製作自己APP並且上架的想法，不管是為了找工作還是自我實現。我當然也不例外，學習的最初我就想做一款記帳APP，但市面上和記帳相關的APP真的數不勝數！所以我一度往其他方向發想，可是怎麼想只想得到 “還可以” 的主題，自己都沒有共鳴了怎麼能在製作時享受其中？</p><p>後來某次和朋友聊天之後被點醒了，「怎麼可能在短短時間內，想到十幾年來別人都想不到的創意？」我才回過神來，我是要成為iOS APP開發工程師，又不是要成為iOS APP創意企劃師！🤣</p><p>最後我回到自己身上發想，在生活上我需要什麼樣的APP？身為小資一族，清楚自己的金錢流動是非常重要的，當然要記帳！但不只記帳，小資男女們在為生活努力奮鬥的同時，也免不了會有一些心願想要達成，例如：出國玩、買iPhone、吃大餐…沒錯！我需要記帳，也需要儲蓄來達成我的各種生活心願，所以最終我的APP就決定是💡心願記帳💡。</p><blockquote><strong><em>心願記帳</em></strong></blockquote><p>為了讓想像中的APP更清晰，我製作了簡單的企劃，一方面是讓自己對整個APP的架構清楚，一方面是有問題找人討論時能比較快進入狀況。接下來就害羞地跟大家分享我的APP模型！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*OyIK1mdUnGRGL1phXmOnCg.png" /></figure><p>老實說一開始我規劃的功能沒有這麼多，是經過許多朋友給意見還有和彼得潘討論過後的結果…變這麼龐大?我真的很擔心自己到底做不做得出來🤪不過在製作過程中一定會有想法上的改變，功能也多少會有加加減減，所以這只是模型不是成品不要太執著😤！我的心願記帳APP最終會變成什麼樣就讓我們且走且看？哈哈！</p><p>心願記帳Part.01到這邊結束，我會努力的🙇🏻‍♀️🙇🏻‍♀️🙇🏻‍♀️</p><p><strong><em>未完待續，敬請期待…</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e1cadc4c716" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/task-part-01-%E6%88%91%E5%88%B0%E5%BA%95%E8%A6%81%E5%81%9A%E4%BB%80%E9%BA%BCapp-1e1cadc4c716">#Task：Part.01–我到底要做什麼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[#86 利用 SwiftUI 的 Path 繪圖：GitHub icon]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/86-%E5%88%A9%E7%94%A8-swiftui-%E7%9A%84-path-%E7%B9%AA%E5%9C%96-github-icon-7521d826d01f?source=rss-7c45ce91e4d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/7521d826d01f</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[path]]></category>
            <dc:creator><![CDATA[Yuwen Chiu]]></dc:creator>
            <pubDate>Wed, 18 Sep 2019 15:49:43 GMT</pubDate>
            <atom:updated>2019-09-18T15:49:43.661Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SPiwK0F7M2cCzTDO6fLyNA.png" /></figure><p>SwiftUI發表之後還沒好好研究它…就從有趣的畫圖開始吧！這隻應該是貓🐱？的圖案是GitHub的icon，因為線條滿簡單的所以就用它來小試身手～有興趣就往下看我的程式碼吧！</p><blockquote><strong><em>Path</em></strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd8fc4e287cc30877e59f30d63be0f64/href">https://medium.com/media/dd8fc4e287cc30877e59f30d63be0f64/href</a></iframe><p>大功告成！其實一開始得知SwiftUI發表的時候很驚嚇，因為覺得原本的Storyboard、AutoLayout技巧都還沒熟練怎麼又有新技術了🤯，但接觸之後其實沒有想像中可怕啦～更多SwiftUI的奧妙就讓我們細細探索吧🥳</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7521d826d01f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/86-%E5%88%A9%E7%94%A8-swiftui-%E7%9A%84-path-%E7%B9%AA%E5%9C%96-github-icon-7521d826d01f">#86 利用 SwiftUI 的 Path 繪圖：GitHub icon</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>