<?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 Liyao Chen on Medium]]></title>
        <description><![CDATA[Stories by Liyao Chen on Medium]]></description>
        <link>https://medium.com/@gliyao?source=rss-455eede53a04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*e_WZhMBFYyZm1F1G.JPG</url>
            <title>Stories by Liyao Chen on Medium</title>
            <link>https://medium.com/@gliyao?source=rss-455eede53a04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 12:55:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gliyao/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[順序如何影響可讀性]]></title>
            <link>https://medium.com/@gliyao/%E9%A0%86%E5%BA%8F%E5%A6%82%E4%BD%95%E5%BD%B1%E9%9F%BF%E5%8F%AF%E8%AE%80%E6%80%A7-a43a05245ea3?source=rss-455eede53a04------2</link>
            <guid isPermaLink="false">https://medium.com/p/a43a05245ea3</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Liyao Chen]]></dc:creator>
            <pubDate>Mon, 03 Aug 2020 06:11:31 GMT</pubDate>
            <atom:updated>2020-08-03T06:11:31.079Z</atom:updated>
            <content:encoded><![CDATA[<p>有個問題一直困擾我很久，在單元測試的 Assertion 中，該把結果放在前面，還是該把預期結果放在前面？</p><p>以一個簡單計算機為例子，像是這樣</p><pre><em>let calculator = Calculator()<br>let result = calculator.add(4, 3)</em></pre><pre><em>// Case 1<br>XCTAssertEqual(7, result)</em></pre><pre><em>// Case 2<br>XCTAssertEqual(result, 7)</em></pre><p>雖然兩個例子有著相同的效果也都正確，但如果你仔細讀起來，他們還是有一些意思上的不同，讓我們來把它翻譯成中文</p><p>Case 1: 有個計算機將 4 與 3 相加後， <strong>7 等於結果</strong><br>Case 2: 有個計算機將 4 與 3 相加後，<strong> 結果等於 7</strong></p><p>對我來說，後者在閱讀上更符合直覺，讀起來更輕鬆。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a43a05245ea3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[為什麼我不用 Squash]]></title>
            <link>https://medium.com/@gliyao/%E7%82%BA%E4%BB%80%E9%BA%BC%E6%88%91%E4%B8%8D%E7%94%A8-squash-65a2ddaa83fc?source=rss-455eede53a04------2</link>
            <guid isPermaLink="false">https://medium.com/p/65a2ddaa83fc</guid>
            <category><![CDATA[git-squash]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Liyao Chen]]></dc:creator>
            <pubDate>Thu, 12 Sep 2019 09:48:54 GMT</pubDate>
            <atom:updated>2019-09-16T04:12:25.416Z</atom:updated>
            <content:encoded><![CDATA[<h3>為什麼我不用 Squash and merge</h3><p>這是一個失敗案例，主要是說我做了某件蠢事導致浪費很多時間，還有從這個教訓當中我學到了什麽。</p><h4>Squash and merge</h4><p>它是 Github PR 的其中一項功能，當你要把 PR 合併回指定分支時可以選擇要用哪種方式合併，如圖所示。</p><p>最早認識這個功能是在前公司，當時的同事跟我說他們 team 每個 PR 都用 Squash and merge 通通壓成一個 commit ，這樣 git 線圖就會很好看，每個功能就是一個點。</p><p>雖然能理解線圖好看的重要，但是總覺得如果都壓成一個 commit ，那我之前費心把每一個 commit message 寫的那麼清楚幹嘛？ 都加再一起一大包就好啦。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vpCTBNmZGd5OXk5i2FrJGA.png" /><figcaption>Github PR merge options</figcaption></figure><p>今年二月我剛進公司就試著把<strong>靜態分析</strong>引入以此提升程式碼品質，的確也抓到很多小問題，於是我興沖沖就把一千多行的修改提交到開發分支，沒想到就此埋了一個地雷給自己。</p><p>時間快轉到六月份距離死線不遠的前幾天， QE 突然發現一個很嚴重的 Bug ，但不知道是何時產生的，只知道上上上個版本沒問題。</p><p>剛好前陣子學到 git bitsec ，透過 Binary search 的方式很快的就找到出錯的 commit ，你猜的沒錯，找到的就是當時那個一千多行的重構。</p><p>即使在幾個同事的協助下，我們還是花了整個下午才找到究竟是哪裡改壞，幾乎浪費整個 iOS team 一整個下午的開發能量。</p><h4>git bisect</h4><p>它是一種幫助你快速找到壞掉的 commit 的工具，原理是用 Binary Search 演算法的核心概念，每次的操作可以剔除掉一半的 commits ，再重複 N 次的超做後能找到問題發生的 commit。有興趣可以看這篇<a href="http://www.ruanyifeng.com/blog/2018/12/git-bisect.html">阮一峰老師的文章</a>。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/0*nu-6U8aHUOKPKvvd.png" /><figcaption>git bisect</figcaption></figure><h4>這個錯誤中我學到什麼？</h4><p>我們永遠不會知道自己何時會搞壞程式碼，保持良好的開發習慣，盡可能讓提交越小越好。</p><p>之前遇過蠻多人會為了讓線圖好看而使用 <strong>squash and merge</strong>，本來我對它是沒有太多想法，不知道該用或不用。</p><p>但經過這次的慘痛教訓我肯定是不會用它了，寧願線圖醜也不想浪費時間上演名偵探柯南的戲碼。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65a2ddaa83fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[還技術債的藝術 II]]></title>
            <link>https://medium.com/ichef/%E9%82%84%E6%8A%80%E8%A1%93%E5%82%B5%E7%9A%84%E8%97%9D%E8%A1%93-ii-c89650cc9863?source=rss-455eede53a04------2</link>
            <guid isPermaLink="false">https://medium.com/p/c89650cc9863</guid>
            <category><![CDATA[技術債]]></category>
            <category><![CDATA[軟體工程]]></category>
            <dc:creator><![CDATA[Liyao Chen]]></dc:creator>
            <pubDate>Tue, 25 Jun 2019 06:01:02 GMT</pubDate>
            <atom:updated>2019-06-28T04:22:57.431Z</atom:updated>
            <content:encoded><![CDATA[<h4>一魚多吃，除技術債同時提升效能</h4><p>本篇文章是<a href="https://medium.com/ichef/%E9%82%84%E6%8A%80%E8%A1%93%E5%82%B5%E7%9A%84%E8%97%9D%E8%A1%93-i-6921cf750f8e"> 💸還技術債的藝術 I </a>的續集，沒看過的觀眾建議先連過去看看。</p><p>漫無目的從 Code base 找技術債並不是個聰明的作法，雖然這麼做你一定能馬上找到數十個技術債的嫌疑犯，但很可能他們都是清白的，就像是在路上隨機抓人就懷疑他犯法一樣，我不會說這個方法完全無效，只是它相對會花上更多時間。</p><h3>怎麼做才是有效率的呢？</h3><p>這個時機很簡單，你開發新功能的時候。</p><p>當你開發新功能時多多少少會接觸到原有的程式碼，為了要使用它們你會更仔細去審視實作細節，此時你很可能會發現原有程式碼的缺陷，但這個時候請先不要急著解決它，因為你現在的首要任務是<strong>完成新功能的開發</strong>，先把它們放到待辦事項中，等功能做一個段落時提出來與團隊成員討論，並隨著開發時程的步調來調整決定<strong>還哪個債</strong>及<strong>何時還債</strong>。</p><p>如果每遇到一個技術債就開支線任務的話你會遇到許多問題：</p><h4><strong>大量的 Context switching</strong></h4><p>這對生產力非常有害，人腦跟電腦不一樣的地方是我們每次 Context swtich 都會耗費巨量的能量，而每個人每天的注意力能量是非常有限的。相信你也過這樣的經驗，當你同處理多件事情時很容易覺得累，每次回到另一個 Context 都會覺得『我剛剛處理到哪了？』</p><h4><strong>重複的解決相同的問題</strong></h4><p>假如你總共遇到三個相似的技術債，但因為你的方法是來一個打一個，因此會犧牲了有可能批次處理的機會，相當可惜。</p><h4><strong>解決不了的技術債</strong></h4><p>也許這個技術債是 NP 問題，一時之間是無法解決的，不能解決頂多就是浪費了時間去試，怕就怕你以為你解決了，但其實產生了的未知問題，更糟的情況是你為此耽誤太多時間而延誤新功能開發時程。</p><p>你沒解決技術債，也沒完成功能開發，開了太多支線任務，導致你主線任務根本破不完或是熬夜才能破完，你不會想要落此下場的。</p><h3>實際案例</h3><p>故事是這樣的，我在開發某個跟會員相關的功能過程中發現一個問題，因為電話號碼在會員系統中有唯一性，也就是不會有同兩個人擁有同一個電話號碼，所以在新增(修改)會員電話時必須做檢查，確認該電話在系統中還沒被使用，才能讓這個修改成立。</p><p>這個需求簡單明瞭但舊有的程式碼卻大有問題，其資料結構是把所有會員資料存在一個 Array 當中進行操作。</p><p>也就是說，當進行電話號碼欄位比對時會<strong>循序</strong>檢查 Array 中的每一筆會員的電話號碼是否與目標值相同，全部會員資料有多少筆就比對多少次，這是一個沒有效率的實作方法。而其方法同時也影響了「查找此會員是否存在」，或是「其電話號碼是否已被使用」的功能，以演算法的術語來說就是時間複雜度是 O(N)</p><p>不僅如此，也因為把會員資料全部倒入記憶體中佔據大量空間，而大多時候它們是閒置的資料，只有在操作會員相關資訊時才有作用，而造成無謂的記憶體浪費。</p><p>這個誤用的資料結構造成了「搜尋效能低」及「濫用記憶體」的問題。</p><p>由於隨著該功能上線，我們預期將會大大的提升各餐廳的會員數量，進而將放大其問題的嚴重性。這個技術債會隨著公司的 Business scale 升級而被放大，而現在正是還它的好時機。</p><p>在幾次 Stand up 會議討論後主管也認為該問題很嚴重值得花時間解決。</p><h3>技術債考古</h3><p>做任何決定前，先確保擁有足夠多的資訊來輔助判斷，避免在資訊不足的情況下做出錯誤決定。</p><p>於是我向同事請教當時的時空背景，先前之所以把所有資料放入 Array 之中是當時常常遇到資料庫毀損，在找不到原因的情況下先加了一層快取來避免直接對資料庫操作。</p><p>「不過現在我們很少資料庫毀損了，這段應該可以改。」他說。</p><h3>衡量解決方案</h3><p>在做之前先衡量有哪些解決方案，並衡量其優缺點、實作難度、你所擁有的時間等維度來選擇最佳的解決方案。</p><h4><strong>方案一：建立 HashMap 加速搜尋</strong></h4><p>於是很直覺的想把 Array 改成 HashMap ，但這麼做的缺點很明顯，需要維護多個 HashMap，像是 UUID to 會員，電話 to 會員等等。而且這麼做並沒有解決記憶體使用量的問題，反而有可能上升。</p><p>*實作複雜度較高，且問題只解決一半。</p><h4><strong>方案二：回歸 SQL 正途</strong></h4><p>後來想也許該用更簡單的方式，也許根本不需要 Cache，直接用資料庫現 SQL query 來實作電話比對，但我不確定自己是否夠熟悉 SQL。(因為還有另一個技術債，我們把會員的資料是壓成 JSON 字串，直接存入某個欄位，藉此來設計一種通用的 Table)</p><p>*實作複雜度較低，問題有機會可以一次解決。<br>*不確定因素是：對 SQL 不熟</p><p>基於「不要過早最佳化」及「不要過度設計」的想法，再加上<strong>方案二</strong>才能同時<strong>加快搜尋</strong>以及<strong>減少記憶體使用量</strong>，於是答案就很明顯了。</p><p>值得一提的是這裡請你以<strong>結果導向來做決策</strong>，無論實作方法的困難度最終我們在乎的是<strong>成果</strong>。很多時候我們會落入<strong>過度設計</strong>的陷阱裡，使用了多複雜的設計最後發現別人看不懂難以維護，這樣一來反而本末倒置。</p><h3>衡量成果</h3><p>有了初步的假設與解決方案，接著要來試著驗證它們。</p><p>如果少了這個步驟，將難以確認修改到底改善多少？值不值得我們花時間修改？於是簡單做了個實驗來看看修改前後的差異。</p><h4><strong>搜尋時間</strong></h4><p>在 200k 筆會員資料的情況下，用原方法確認「單筆電話號碼是否被使用」的時間是 2.05 秒</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*grBMpU-gvJg8JEVsyJK5Yg.png" /><figcaption>原方法耗時 2.05 秒</figcaption></figure><p>在同樣會員數情境下，新的方法只需要 0.051 秒</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vNrka9oQytHm6223quspRA.png" /><figcaption>新方法耗時 0.051 秒</figcaption></figure><p>在效能方面結果相當顯著，該方法從 2 秒下降到 0.05 秒。</p><p>效能提升大約 <strong>40</strong> 倍。</p><h4><strong>記憶體使用量</strong></h4><p>在會員數 28k 的情境下最高記憶體使用量從 450MB 降到 344MB 。</p><p>大約降低 <strong>100MB</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OG43Vf5eczD3yhO0UHJ6og.png" /><figcaption>記憶體使用量差異示意圖</figcaption></figure><h3>結語</h3><p>以前我也是看到技術債就馬上動手去修改，恨不得把房間整理的一塵不染。</p><p>但我後來了解時間是有限的，而程式碼改善是無限的。隨著時間的流逝你永遠可以找到更好的方式還債(又或者不用還)。永遠有新出的 framework 或者是 Open source 幫你解決了過去某個問題。</p><blockquote>用聰明的方法還債，將會使你工作輕鬆很多，也對公司有更多貢獻。<br>用健康的心態去面對技術債，會讓你的人生好過很多。</blockquote><p>把心思與力氣放在最重要的事情上，才能在有限的人生裡發揮最大效益。</p><p>如果覺得寫得不錯的話拍個手吧👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c89650cc9863" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ichef/%E9%82%84%E6%8A%80%E8%A1%93%E5%82%B5%E7%9A%84%E8%97%9D%E8%A1%93-ii-c89650cc9863">💸還技術債的藝術 II</a> was originally published in <a href="https://medium.com/ichef">iCHEF</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[還技術債的藝術 I]]></title>
            <link>https://medium.com/ichef/%E9%82%84%E6%8A%80%E8%A1%93%E5%82%B5%E7%9A%84%E8%97%9D%E8%A1%93-i-6921cf750f8e?source=rss-455eede53a04------2</link>
            <guid isPermaLink="false">https://medium.com/p/6921cf750f8e</guid>
            <category><![CDATA[技術債]]></category>
            <category><![CDATA[軟體工程]]></category>
            <dc:creator><![CDATA[Liyao Chen]]></dc:creator>
            <pubDate>Fri, 21 Jun 2019 09:31:01 GMT</pubDate>
            <atom:updated>2019-06-25T07:19:23.010Z</atom:updated>
            <content:encoded><![CDATA[<h4>消除對技術債的傲慢與偏見</h4><p>你是否也有接手過別人程式碼的經驗？</p><p>無論是加入新的專案或是工作環境，我們都有很大的機會承接這些遺產。作為一個新進成員，在閱讀舊有程式碼時難免會有許多疑問。</p><ul><li>為什麼這裡會這樣寫？</li><li>為什麼這裡會需要這樣的 Workaround？</li><li>為什麼這裡要這樣設計？</li><li>為什麼會寫的這麼差？</li></ul><p>『全部重寫好了？！』 難免會這樣想。</p><h3><strong>為什麼會有技術債？</strong></h3><p>請先等一等，思考為什麼這些技術債存在？也許是下列幾種原因：</p><ul><li>時辰壓力：為追趕產品上線時程，不夠時間考慮周全</li><li>需求變更：過去符合需求但不符合新的需求</li><li>技術演進：新的程式碼語法只要一行就能解決</li></ul><p>如果從一間企業的成長歷程中去看技術債這個議題，你會發現在草創時機不太會請到厲害的工程師加盟。</p><p>為什麼這樣說呢？</p><h4>從軟體工程師的角度來看</h4><p>以成長面來看，新創公司變動很快，通常是邊摸索需求邊開發功能，而團隊中很可能只有你一位 iOS 工程師，在孤軍奮戰加戰況危急的情況下你很難有時間好好累積良好的開發知識與經驗。</p><p>從風險與報酬面來看，參加新創的風險很高，但報酬率不一定高，也許先加盟較穩定的企業，等新創公司的價值被證明再帶刀投靠也不遲。</p><h4><strong>從公司的角度來看</strong></h4><p>當商業模式還未被證明可行，又有資金壓力的前提下，創業家必須要在<strong>花多少成本</strong>來<strong>請多厲害的人</strong>這兩件事情上取得平衡。</p><p>如果要請 A 咖勢必要付出比較多資金成本，而且人家也不一定會願意加盟。<br>如果請 C 咖資金成本比較低，但當然技術債會欠得多。</p><p>為了讓公司存活必須要積極的驗證市場，因此需求劇烈變動是可預期的，而在需求頻繁修改的情況下，幾乎不可能設計出好的架構，因為設計好的架構也是需要<strong>時間</strong>跟<strong>經驗</strong>。</p><p>綜合上述兩個角度來看，創業初期就有超棒的軟體架構不是不可能，但不是<strong>活下去的必要條件</strong>。</p><blockquote>技術債是必然的產物，<strong>有程式碼就有技術債</strong>。</blockquote><h3>不需要還的技術債</h3><p>公司開了 3 個產品線，為了快速驗證市場需求同時兼顧公司營運成本，一年後會只留下賺錢的產品。在這個情況下，你會秉持<strong>職人心態</strong>每行程式碼斤斤計較而<strong>拖慢產品進程</strong>，還是快速開發適時留下技術債？</p><p>現實是<strong>當產品下線時，程式碼再漂亮架構再好都是沒有意義的</strong>。</p><blockquote><strong>你要先活著才能還債。</strong></blockquote><blockquote>又或者說，<strong>不活著就不用還債。</strong></blockquote><p>講到這你已清楚技術債的生長模式，要處理它就不會這麼難受。</p><h3><strong>更健康的心態去面對技術債</strong></h3><p>想像你是一位籃球選手，在比賽下半場教練把你換上場，此時球隊輸 20 分，你會覺得？</p><ol><li>輸 20 分根本追不回來，派我上來幹嘛？</li><li>覺得球隊就靠我了，把球都給我單打</li><li>能追多少算多少，一球一球打好來</li></ol><p><strong>最壞的時代是最好的機會</strong><br>你也可以想這是證明自己能力的好機會，除了幫助公司解決當前的難題，自己也能從中獲得成就感，當然也有使用者因此而受惠等等的好處。</p><p>而工作這回事就是公司花錢交換你來解決問題。</p><h3><strong>選擇值得還的技術債</strong></h3><p>綜觀整個 Code base ，需要還的債滿坑滿谷，究竟該先處理哪一個？</p><p>在這提供兩個考量的指標「還債的效益」，以及「還債的困難度」。</p><h4><strong>還債的效益</strong></h4><p><strong>學貸，房貸，信用卡債，先還哪個？<br></strong>房貸跟學貸的利率比較低的，而信用卡債則是相對高。也就是說在同樣的時間，要付更多利息在信用卡債上，因此優先償還信用卡債是比較聰明的選擇。</p><p><strong>醫院急診室先救誰？<br></strong>突然間有很多病人湧進急診室，有些病患的問題比較緊急，10 分鐘內不處理可能會死亡，有些病患相對不危及性命，面臨這樣的問題應該怎麼選擇？</p><p>作為醫生的救援原則就是先避免死亡數字上升，再服務其他病人。</p><p>從上述兩個案子可以歸納出<strong>處理順序的重要性</strong>，債不是先來的先還，債也不是最大的先還，注意順序可以幫助你相對輕鬆的償還債務。</p><h4><strong>還債的困難度</strong></h4><p>假如有2個病患危及性命，其中有一個手術難度較高，需要全身麻醉的大型手術，且其成功率僅30%。</p><p>另一個病患同樣也是性命垂危，僅需要小手術即可，其手術成功率為 90%。</p><p>只能<strong>先</strong>救一個，你會怎麼選擇？</p><p>大範圍的重構或重寫，難度越高且越有可能造成其他問題，從上面的例子可以看出來，在同樣效益前提下，相對較小較容易的任務代表花費時間越短，總體效益會更高。</p><h3>未完待續</h3><p>技術債是一個有趣的議題，只要你還有在寫程式就很有可能遇到，不論你加入的是 Facebook, Google 等世界級的軟體公司，還是一些小型軟體公司服務都避不開它。</p><p>現在用的最新技術，也會隨著時間過去日換星移而被人們當成技術債。</p><p>技術：『想當初你是這麼愛我的不是嗎？』</p><p>下集<a href="https://medium.com/ichef/%E9%82%84%E6%8A%80%E8%A1%93%E5%82%B5%E7%9A%84%E8%97%9D%E8%A1%93-ii-c89650cc9863">💸還技術債的藝術II</a>會以實際案例跟大家分享我們有哪些技術債，我們怎麼去選擇優先還哪個，還有在面對抉擇時我們怎麼權衡。</p><p>如果覺得寫得不錯的話拍個手吧👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6921cf750f8e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ichef/%E9%82%84%E6%8A%80%E8%A1%93%E5%82%B5%E7%9A%84%E8%97%9D%E8%A1%93-i-6921cf750f8e">💸還技術債的藝術 I</a> was originally published in <a href="https://medium.com/ichef">iCHEF</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WWDC 18 讀書會]]></title>
            <link>https://medium.com/honestbee-tw-engineer/wwdc-18-%E8%AE%80%E6%9B%B8%E6%9C%83-acb4e501dda6?source=rss-455eede53a04------2</link>
            <guid isPermaLink="false">https://medium.com/p/acb4e501dda6</guid>
            <category><![CDATA[wwdc-2018]]></category>
            <category><![CDATA[group-study]]></category>
            <category><![CDATA[honestbee]]></category>
            <dc:creator><![CDATA[Liyao Chen]]></dc:creator>
            <pubDate>Mon, 27 Aug 2018 09:01:07 GMT</pubDate>
            <atom:updated>2018-08-27T09:21:16.841Z</atom:updated>
            <content:encoded><![CDATA[<p>活動期間：6/26 ~ 8/7 每週二晚上 7點至9點<br>活動地點： Honestbee 辦公室</p><p>由於場地跟經費的關係，本次活動算是邀請制大家有緣明年再共襄盛舉。</p><p>WWDC 是 Apple <strong>W</strong>orld<strong>w</strong>ide <strong>D</strong>evelopers <strong>C</strong>onference 的簡稱，每一年 6 月份蘋果會在矽谷舉辦，也可以說是蘋果一年一度的軟體發表會，而該年發表的軟體將會隨著 9 月的硬體發表會一同發佈。 以 WWDC18 為例，發表 iOS 12 系統會搭載下一代 iPhone 一起在 9 月釋出。</p><p>所以每年的 6 月就是蘋果開發者傷腦筋的時候，高興的是又有新技術可以給使用者更好的體驗，煩惱的是看不完的 Sessions 排山倒海而來。如果你身在開發者數量不多的組織裡很找不到人一起分擔，所以最後就變成乾脆不看了…</p><p><strong>為什麼要辦讀書會?</strong></p><p>希望集結眾人的力量一起來攻克 WWDC。 根據 Divide and conquer 演算法中的核心概念，只要我們能夠把 Topic 拆得夠細，每個人負責一個部分，我們終究會打敗 WWDC 大魔王。</p><p>雖然各自去讀完所有 Session 也能獲得所有知識，但更有趣的是大家聚在一起透過討論過程中激發不同的想法，每個人都在這過程中一起成長</p><p><strong>本次讀書會的重點</strong></p><ul><li>半小時 Topic 重點整理，希望點到就好有興趣的人再去深讀</li><li>資深工程師們對 Topic 見解及討論</li><li>大家對新技術應用層面的想像</li></ul><h4>活動紀錄</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*ra1fuRNmrXLel64Jz6eEwg.jpeg" /><figcaption>波肥大大開示</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*l68VeRk7G0GYxMC-460wfA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Dd88Ul3hqzMcWKGERP1VSQ.jpeg" /><figcaption>大家專心的神情</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y07MBy1y580qro_XX9OrUg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RT6-Myc2UXpcxrZejrJwOA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*wuYH-Yuvlj3t3XcEth0buw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*ZLDfBNJSnShFC1C9a91LQw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*g-LoYTOk1jlVNneSFcpHcQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*_2KbSWf7MRumy9ICtISU0Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*j-k2vV6qpIVc616LaKDk7A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*-QT_kw5yxu6jMqB_YUuwYg.jpeg" /></figure><h4><a href="https://paper.dropbox.com/doc/WWDC18-Party--ALOIykJrbHNasCNqM6kiX_MKAg-OPzMwfdLEsieCJKEzvryp">讀書會影片及投影片</a></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6nub0RADkkkc1ZmwNUPfJQ.png" /><figcaption>請點上方標題或下方連結</figcaption></figure><p><strong>Reference</strong><br><a href="https://paper.dropbox.com/doc/WWDC18-Party--ALOIykJrbHNasCNqM6kiX_MKAg-OPzMwfdLEsieCJKEzvryp">https://paper.dropbox.com/doc/WWDC18-Party--ALOIykJrbHNasCNqM6kiX_MKAg-OPzMwfdLEsieCJKEzvryp</a></p><h3>後記</h3><p>雖然每次辦完讀書會都很累很想死，都會想說我再也不要辦了，但是最後還是會辦 (完全不知道在幹嘛 XD)</p><p>但不得不說每次辦讀書會總會有滿滿的收穫，畢竟一個人要學完所有知識是不可能的嘛！</p><p>特別感謝所有願意花額外時間參加此讀書會的朋友，我們做到了！</p><p>下次再一起組隊打怪吧！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acb4e501dda6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/honestbee-tw-engineer/wwdc-18-%E8%AE%80%E6%9B%B8%E6%9C%83-acb4e501dda6">WWDC 18 讀書會</a> was originally published in <a href="https://medium.com/honestbee-tw-engineer">honestbee-tw-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WWDC 18 Sessions 總覽]]></title>
            <link>https://medium.com/ios-nerd/wwdc-18-sessions-%E7%B8%BD%E8%A6%BD-8ce1cdfd1053?source=rss-455eede53a04------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ce1cdfd1053</guid>
            <category><![CDATA[wwdc18]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Liyao Chen]]></dc:creator>
            <pubDate>Tue, 12 Jun 2018 03:48:54 GMT</pubDate>
            <atom:updated>2018-06-12T03:48:54.220Z</atom:updated>
            <content:encoded><![CDATA[<p>此文件列出 2018 年 WWDC 所有 Sessions 的連結跟描述，希望能幫助大家快速找到想看的內容。這個文件是由 <a href="https://medium.com/u/a2be70916ca4">Nalydadad</a> 提供的工具 <a href="https://github.com/nalydadad/WWDC_Crawler/tree/master">WWDC_Crawler</a> 所抓取。</p><h4>A Guide to Turi Create</h4><p>Turi Create is an open source toolset for creating Core ML models, for tasks such as image classification, object detection, style transfers, recommendations, and more. Learn how you can use Turi Create to build models for your apps. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/712/">link</a></p><h4>A Tour of UICollectionView</h4><p>UICollectionView is a flexible, powerful tool to help you achieve great user experiences in your applications. Hear how you can leverage these rich APIs to rapidly move from initial design ideas to polished shipping applications. Topics range from getting started to advanced update animations and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/225/">link</a></p><h4>AVContentKeySession Best Practices</h4><p>AVContentKeySession allows for the management of FairPlay content decryption keys for HTTP Live Streaming. It offers a simplified key loading process that provides applications with control over the lifecycle of content keys, and features such as dual-expiry keys for offline movie rentals. Learn… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/507/">link</a></p><h4>AVSpeechSynthesizer: Making iOS Talk</h4><p>Speech can enhance the audio experience of your app, whether you are generating spoken feedback for accessibility, or providing critical information beyond simple alerts or notifications. AVSpeechSynthesizer produces synthesized speech from text and allows you to control and monitor the progress… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/236/">link</a></p><h4>Accessible Drag and Drop</h4><p>Drag and Drop is a powerful API that allows apps to share and communicate data. No matter how you decide to implement Drag and Drop, there’s a way to make it work for people with accessibility needs. Learn the details as we dive into accessible Drag and Drop for iOS. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/241/">link</a></p><h4>Accessing Health Records with HealthKit</h4><p>HealthKit provides a consolidated repository for a variety of data including health records containing information such as lab results, immunizations, and medications downloaded directly from institutions. Discover new health records classes and types created to provide easy access to high-level… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/706/">link</a></p><h4>Adding Delight to your iOS App</h4><p>iOS contains powerful technologies you can use to make your app truly delightful. Learn how to take your app to the next level with easy-to-implement features such as Handoff and External Display support. Preserve that feeling of magic in your app with pro-tips that combine animations, gestures… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/233/">link</a></p><h4>Advanced Dark Mode</h4><p>Step deeper into Dark Mode adoption in your macOS application. Learn about the powerful Cocoa technologies at the core of Dark Mode, and take a detailed look at the APIs and best practices for adapting to this beautiful new look. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/218/">link</a></p><h4>Advanced Debugging with Xcode and LLDB</h4><p>Discover advanced techniques, and tips and tricks for enhancing your Xcode debugging workflows. Learn how to take advantage of LLDB and custom breakpoints for more powerful debugging. Get the most out of Xcode’s view debugging tools to solve UI issues in your app more efficiently. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/412/">link</a></p><h4>Advances in Research and Care Frameworks</h4><p>HealthKit, CoreMotion, and other iOS frameworks combined with the ResearchKit and CareKit open-source projects, provide a deep platform for the creation of game-changing apps for care teams, researchers, and the medical community. Discover new active tasks that leverage calibrated device data and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/205/">link</a></p><h4>Apple Design Awards</h4><p>Join us for an unforgettable award ceremony celebrating developers and their outstanding work. The 2018 Apple Design Awards recognize state of the art iOS, macOS, watchOS, and tvOS apps that reflect excellence in design and innovation. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/103/">link</a></p><h4>Automatic Strong Passwords and Security Code AutoFill</h4><p>Passwords and security codes are a modern necessity required for security and privacy. iOS 12 eases the tedious aspects of account setup and sign-in by automatically suggesting and using strong, unique passwords \u2014 even from within apps \u2014 and by bringing one-time codes to the QuickType bar so… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/204/">link</a></p><h4>Automating App Store Connect</h4><p>The new App Store Connect API provides a familiar and highly readable REST API designed to facilitate the automation of many tasks you would typically perform through the Apple Developer website and the App Store Connect browser interfaces. Learn how this API allows you to manage your apps and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/303/">link</a></p><h4>Behind the Scenes of the Xcode Build Process</h4><p>Ever wonder what happens when you build your project in Xcode? Learn how Xcode automates the steps required to build an application, and go behind the scenes to learn how clang, swiftc, and the linker work together to turn your source code into a working program. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/415/">link</a></p><h4>Best Practices and What\u2019s New with In-App Purchases</h4><p>Learn about the latest updates in StoreKit, including offering introductory pricing for subscriptions, requesting ratings and reviews, promoting your in-app purchases within the App Store, and developing in the sandbox environment. Dive deep into best practices for processing transactions and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/704/">link</a></p><h4>Better Apps through Better Privacy</h4><p>At Apple, we believe in building products with both great features and great privacy. Learn how to apply privacy engineering techniques to your apps so you can build trust with users to unlock better experiences and engagement. And find out how new privacy features can benefit you and your users. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/718/">link</a></p><h4>Building Faster in Xcode</h4><p>Build your apps faster in Xcode 10. Learn how to structure your projects and tweak your code to take full advantage of all processor cores. Whether you’ve made a few small code changes you want to give a try, or you’re building your full app for release, these techniques will cut the time it… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/408/">link</a></p><h4>Building for Voice with Siri Shortcuts</h4><p>Siri Shortcuts are a great way to help people execute actions or get information from your app, but shortcuts can be made even more powerful by adding them to Siri to be used with a simple phrase. Learn how you can now customize responses from Siri and add custom UI to make a great shortcuts… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/214/">link</a></p><h4>CarPlay Audio and Navigation Apps</h4><p>Learn how to update your audio or navigation app to support CarPlay. Apps in CarPlay are optimized for use in the car, and automatically adapt to available vehicle screens and input controls. Audio apps can deliver music, news, podcasts, and more. With the new CarPlay framework, Navigation apps… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/213/">link</a></p><h4>Core Data Best Practices</h4><p>As your app gains more customers and becomes more feature-rich, you may find yourself with new problems to solve. Core Data is a powerful tool that has changed a lot over the years. Learn about the new best practices in Core Data, such as how to use concurrency and persistent history, and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/224/">link</a></p><h4>Core Image: Performance, Prototyping, and Python</h4><p>Core Image is the essential framework for handling image processing tasks in your photo and video apps. In this session, we’ll explore new additions to the framework that allow you to achieve great performance in your filter chains and custom CIKernels. We’ll also demo a new approach to… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/719/">link</a></p><h4>Create Your Own Swift Playgrounds Subscription</h4><p>Swift Playgrounds is a revolutionary iPad app to teach coding with the powerful Swift programming language. Learn how to create your own content for Swift Playgrounds using the new template, and find out how to use the subscription format to host your own feed online for others to access. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/413/">link</a></p><h4>Creating Apps for a Global Audience</h4><p>Common assumptions can break when your app is used by a global audience. Learn about the many aspects of creating apps for different regions and languages. Understand how to use fonts and typography, layout techniques, and support text input so your app shines in all languages. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/201/">link</a></p><h4>Creating Audio Apps for watchOS</h4><p>Apps in watchOS 5 have control over audio playback like never before. With a full-fledged background mode for local audio playback using AVFoundation, people can listen to content on the go right from Apple Watch. Learn how to use the new volume control and how to respond to MediaRemote… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/504/">link</a></p><h4>Creating Custom Instruments</h4><p>Understand how custom instruments are useful and when they should be used. Get an in-depth view of the architecture of custom instruments and how to create them. Understand the attributes of a good instrument. Dive into advanced modeling and how to use the CLIPS language. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/410/">link</a></p><h4>Creating Great AR Experiences</h4><p>Engaging AR experiences are easy to start and navigate, persuasively realistic, and highly immersive. Learn best practices for successfully bringing people into an AR experience, teaching them about how to interact and engage with virtual content, and making your AR content look beautiful and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/805/">link</a></p><h4>Creating Photo and Video Effects Using Depth</h4><p>The TrueDepth camera in the iPhone X streams high-quality depth data in real time allowing you to enhance your photo and video apps in fun and creative ways. Dive deep into the principles and best practices for working with depth data, learn how to use the new Portrait Segmentation API for still… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/503/">link</a></p><h4>Data You Can Trust</h4><p>A lot can go wrong when loading data into your app. Whether you work directly with JSON and property lists, or with higher-level APIs such as NSCoding and Codable, learn how to defend your customers and secure your code against invalid or malicious data. Avoid fatal assumptions by validating… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/222/">link</a></p><h4>Deliver an Exceptional Accessibility Experience</h4><p>Go beyond the basics and create apps with an exceptional accessibility experience. Learn how to design elements that appear in your app for maximum clarity and accessibility. Discover how to enhance the way users interact with your app even when presenting custom views, or drawing complex UI. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/230/">link</a></p><h4>Design Studio Shorts</h4><p>Five short presentations on a range of design topics including: Prototyping AR experiences by using the world around you and low-tech traditional prototyping techniques; Making your app more powerful and expressive with Apple Pencil; Indispensable techniques for presenting your design work;… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/807/">link</a></p><h4>Designing Fluid Interfaces</h4><p>Discover the techniques used to create the fluid and dynamic interfaces of iOS and other Apple platforms. Learn how to design gestures and animations that feel intuitive and natural and will make your app delightful. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/803/">link</a></p><h4>Designing Notifications</h4><p>Thoughtfully designed notifications are a powerful way to communicate timely information to people that they will find valuable and useful. Learn how you can design notifications people want to receive by making them beautiful, helpful, actionable, and respectful of their valuable time and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/806/">link</a></p><h4>Designing Web Content for watchOS</h4><p>watchOS 5 brings web content to Apple Watch by rendering rich HTML in Messages and Mail. Gain insights into how watchOS maintains compatibility with existing web content, and find out what you can do to optimize your web content for Apple Watch. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/239/">link</a></p><h4>Embracing Algorithms</h4><p>When you imagine building a new app, what do you think about? Models, views, and controllers deserve their prominent place in the design process, but we don’t often give the same attention to the underlying work our apps need to do. Understand how to identify and optimize the algorithms in your… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/223/">link</a></p><h4>Engineering Subscriptions</h4><p>Learn the best practices for architecting your subscription infrastructure using StoreKit and server-side logic. Find out about simple engineering techniques to keep your subscribers longer, and how to utilize new tools and APIs to give your subscribers the best experience. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/705/">link</a></p><h4>Getting Ready for Business Chat</h4><p>Business Chat is a powerful way for organizations to connect with customers directly from within Messages. Whether you are a Customer Service Platform provider, a brand looking to integrate chat for customer communication, or a brand app developer looking to extend your iOS app to enhance… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/232/">link</a></p><h4>Getting and Using a Mapkit JS Key</h4><p>MapKit JS uses the JWT standard for ensuring a secure connection between your site and the MapKit JS services. Learn how to create, protect, and use site-specific keys to ensure only your servers are accessing APIs linked to your domain. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/508/">link</a></p><h4>Getting the Most out of Playgrounds in Xcode</h4><p>Discover major advancements in Xcode playgrounds. Learn advanced tips and techniques, hear about new and often overlooked workflows, and rediscover the tools provided when coding in playgrounds. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/402/">link</a></p><h4>Getting to Know Swift Package Manager</h4><p>The Swift Package Manager makes it possible to easily develop and distribute source code in the Swift ecosystem. Learn about its goals, design, unique features, and the opportunities it has for continued evolution. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/411/">link</a></p><h4>High Performance Auto Layout</h4><p>Get a glimpse inside to find out what happens when you add a constraint! Dive into the internals of Auto Layout to develop intuition for how your code affects what happens under the hood. Learn how to measure and refine your approach to Auto Layout and see how its improved performance in iOS 12… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/220/">link</a></p><h4>HomeKit Deep Dive</h4><p>Get a fresh look at the HomeKit APIs. Understand how Siri and the Apple Home App use Action Sets and Accessory Services &amp; Characteristics to provide a great home automation experience. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/231/">link</a></p><h4>I Have This Idea For An App…</h4><p>Do you have an idea for an app that you think would be useful to others, but you don’t know how to make it a reality? You’re not alone! Lots of people are interested in app development, but they aren’t sure how to turn their idea to code and then into a finished app. From first steps to Xcode,… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/203/">link</a></p><h4>Image and Graphics Best Practices</h4><p>Whether it’s for UI elements or a fundamental part of your application, at some point, you have to handle images. This session is packed with engaging insight into how images are handled in iOS including discussion of UIImage, UIImageView, custom drawing in UIKit, plus advanced CPU and GPU… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/219/">link</a></p><h4>Implementing AutoFill Credential Provider Extensions</h4><p>Password AutoFill delivers the ability to fill passwords seamlessly within iOS apps and Safari. Join us to learn how app developers who provide credential management can surface their credentials during sign-in within apps and on the web. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/721/">link</a></p><h4>Inside SwiftShot: Creating an AR Game</h4><p>Developed by Apple, SwiftShot is an energetic and immersive multiplayer AR game built with key iOS technologies. Glimpse behind the curtain and see how SwiftShot was designed and developed using ARKit, SceneKit, and Swift. Understand the intricacies of designing great gameplay for AR, and learn… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/605/">link</a></p><h4>Integrating Apps and Content with AR Quick Look</h4><p>With iOS 12, ARKit includes a built-in viewer for displaying and sharing high-quality 3D content using Pixar’s usdz file format. Get introduced to the capabilities of AR Quick Look and see how to easily integrate AR into your app. Learn best practices for preparing 3D models for AR, and see how… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/603/">link</a></p><h4>Integrating with Photos on macOS</h4><p>Make your apps even better through improved integration with Photos on macOS. We’ll dive deep into the Photos Project Extension API that was introduced in macOS High Sierra and update you on what’s new. You’ll also learn best practices for handling file promises and image URLs to better handle… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/505/">link</a></p><h4>Intentional Design</h4><p>Great app experiences leap off the screen. They are dynamic, immersive, personal, and, above all else, the result of a strong and clear intent. Learn key techniques for being intentional with your design by choosing appropriate metaphors, making extreme choices, and making every interaction feel… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/802/">link</a></p><h4>Introducing ClassKit</h4><p>The new ClassKit framework lets you organize educational content in your app so that teachers can discover and assign specific activities and view students’ progress in the new Schoolwork app. Learn how to adopt ClassKit to your content structure, declare assignable content, and share student… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/215/">link</a></p><h4>Introducing Create ML</h4><p>Create ML is a new framework designed to help you easily build machine learning models using Swift and Xcode. Designed for Simplicity and Performance. Learn how you can build customized models from data that will enable new and powerful features in your apps using Create ML. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/703/">link</a></p><h4>Introducing Dark Mode</h4><p>Hear from the Apple design team about the principles and concepts that anchor Dark Mode. Learn the basics of enhancing your app with this new appearance, and add an experience that people are sure to love. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/210/">link</a></p><h4>Introducing MapKit JS</h4><p>MapKit JS brings Apple Maps to your website. See how MapKit JS provides map rendering that is optimized for various browsers and devices, and supports native gestures such as pinch-to-zoom, two-finger rotate, and more. Learn how to add annotations and overlays, and how to use JavaScript… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/212/">link</a></p><h4>Introducing Natural Language Framework</h4><p>Natural Language is a redesigned framework designed to provide high-performance, on-device APIs for fundamental NLP tasks across all Apple platforms. Through the deep integration of the framework with Core ML and Create ML, you now have the ability to train custom NLP models to perform many… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/713/">link</a></p><h4>Introducing Network.framework: A modern alternative to Sockets</h4><p>The new Network.framework API gives you direct access to the same high-performance user-space networking stack used by URLSession. If you’re considering using Berkeley Sockets in your app or library, learn what better options are available to you. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/715/">link</a></p><h4>Introducing Podcast Analytics</h4><p>Podcasts are created and enjoyed by millions of people around the world. With the addition of Podcast Analytics, podcasters can gather actionable and insightful intelligence into how their show is consumed, while respecting the privacy of their listeners. Learn how to interpret and use these new… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/501/">link</a></p><h4>Introduction to Siri Shortcuts</h4><p>Siri Shortcuts are a powerful new feature in iOS 12 that allow your app to expose its functionality to Siri. This enables Siri to suggest your shortcut at relevant times based on various context. Shortcuts can also be added to Siri to run with a voice phrase on iOS, HomePod and watchOS. Learn how… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/211/">link</a></p><h4>Live Screen Broadcast with ReplayKit</h4><p>ReplayKit 2 provides built-in services for broadcasting your screen from iOS and tvOS to viewers online. See how broadcasts can be started right within Control Center or from standard UI included in your own apps and games. Hear about developing broadcast extensions for ReplayKit 2 and get best… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/601/">link</a></p><h4>Managing Documents In Your iOS Apps</h4><p>Last year we introduced the Files App and an easy way to view, edit, and share documents within your application. Learn best practices for implementing this technology, how to effectively manage documents in your app, and how to avoid common document manager pitfalls. Hear about the difference… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/216/">link</a></p><h4>Measuring Performance Using Logging</h4><p>Learn how to use signposts and logging to measure performance. Understand how the Points of Interest instrument can be used to examine logged data. Get an introduction into creating and using custom instruments. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/405/">link</a></p><h4>Measuring and Optimizing HLS Performance</h4><p>HTTP Live Streaming (HLS) is used to stream live and on-demand content to global audiences. Discover how to adjust and tune stream authoring and delivery elements to improve the viewing experience. Learn how to accurately measure your streaming performance, identify optimization opportunities,… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/502/">link</a></p><h4>Metal Game Performance Optimization</h4><p>Realize the full potential of your Metal-based games by tackling common issues that cause frame rate slowdowns, stutters, and stalls. Discover how to clear up jitter and maintain a silky-smooth frame rate with simple changes in frame pacing. Get introduced to new tools for analyzing rendering… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/612/">link</a></p><h4>Metal Shader Debugging and Profiling</h4><p>Metal provides powerful tools for analyzing shader behavior and optimizing performance. Dive into troubleshooting vertex-stage problems with new geometry viewing capabilities in Xcode. Use the shader debugger to step through vertex, fragment, and compute shader execution line-by-line. Get details… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/608/">link</a></p><h4>Metal for Accelerating Machine Learning</h4><p>Metal Performance Shaders (MPS) includes a highly tuned library of machine learning primitives leveraging the tremendous power of the GPU. With iOS 12 and macOS Mojave, MPS adds capabilities to accelerate the computationally intensive task of training a neural network. Learn performance… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/609/">link</a></p><h4>Metal for Game Developers</h4><p>Metal 2 is Apple-designed graphics software that lets developers build console\u2011style games. Learn key aspects of the Metal architecture that support the techniques for modern high-performance game rendering. See how Metal now enables the GPU to schedule work for itself, allowing complete scenes… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/607/">link</a></p><h4>Metal for OpenGL Developers</h4><p>Metal is the foundation for accelerated graphics and compute on Apple platforms, enabling your apps and games to tap into the incredible power of the GPU. Get introduced to essential Metal capabilities and understand the recommended approach for transitioning OpenGL-based apps onto the Metal API. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/604/">link</a></p><h4>Metal for Ray Tracing Acceleration</h4><p>Metal Performance Shaders (MPS) harnesses the massive parallelism of the GPU to dramatically accelerate calculations at the heart of modern ray tracing and ray casting techniques. See how ray tracing can provide greater realism in 3D scenes through improved shading, soft shadows, and global… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/606/">link</a></p><h4>Metal for VR</h4><p>On macOS, Metal 2 adds specialized support for virtual reality (VR) rendering and external GPUs. Learn about new features and optimizations to take advantage of these technologies within your Metal 2-based apps and games. Understand best practices for scheduling workloads across multiple GPUs and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/611/">link</a></p><h4>MusicKit on the Web</h4><p>MusicKit has enabled the creation of new, compelling, and engaging Apple Music powered app experiences. With the introduction of MusicKit on the web, as a developer, you can now bring Apple Music powered experiences to the web. Learn how to use declarative markup or javascript to enable Apple… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/506/">link</a></p><h4>New Localization Workflows in Xcode 10</h4><p>The localization process in Xcode 10 has been updated to aid you through the lifecycle of exporting, importing, and testing localized content in your apps. See new functionality added in Xcode 10 and learn how the new localization catalog helps you build world-class, localized apps. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/404/">link</a></p><h4>New Ways to Work with Workouts</h4><p>Tracking workouts with Apple Watch is popular with fitness professionals and novices alike. See how the new workout API streamlines the entire lifecycle of a workout, complete with ability to restart a session after a crash to prevent you from losing data. Learn how the new workout classes,… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/707/">link</a></p><h4>Object Tracking in Vision</h4><p>Vision is a high-level framework that provides an easy to use API for handling many computer vision tasks. We’ll dive deep into a particularly powerful feature of Vision\u2014tracking objects in video streams. Learn best practices for using Vision in your app. Gain a greater understanding of how… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/716/">link</a></p><h4>Optimizing App Assets</h4><p>Learn how to use assets to bring visually compelling and data efficient artwork to your apps, leveraging new features in iOS 12. Gain insight into organizing, optimizing, and authoring artwork assets by using asset catalogs to their fullest. Learn techniques to better streamline workflows between… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/227/">link</a></p><h4>Optimizing Your App for Today\u2019s Internet</h4><p>Learn what Apple has been doing to help your app get the most out of the network with the least effort. Let Apple’s networking APIs do the heavy lifting for you. Learn best practices for getting top networking performance from your app using the URLSession APIs. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/714/">link</a></p><h4>Platforms State of the Union</h4><p>2018 Platforms State of the Union <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/102/">link</a></p><h4>Practical Approaches to Great App Performance</h4><p>All apps benefit from a focus on performance and an increase in overall responsiveness. This information packed session gives you strategies for fixing performance problems using Instruments and other tools. Additionally, get practical advice based on experience in tuning Apple’s own apps… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/407/">link</a></p><h4>Quick Look Previews from the Ground Up</h4><p>Quicklook Previews are an easy way preview documents in your app. Hear about the basics as well as some advanced implementations. Learn to present a variety of types of documents from within your app without reinventing the wheel, and make sure your custom file format works great with the… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/237/">link</a></p><h4>Siri Shortcuts on the Siri Watch Face</h4><p>Learn how to use Siri Shortcuts to bring glanceable information and custom interactions to the Siri watch face. Walk through how to create a compelling user experience by providing relevant shortcuts and by donating interactions from your app. See how these experiences can be created from both… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/217/">link</a></p><h4>Source Control Workflows in Xcode</h4><p>Xcode integrates with GitHub, Bitbucket, and GitLab to help you manage your source code, back up your files, and collaborate with others. Find out how to easily see the changes in your project right in the source editor, and learn how to use Xcode for common source control workflows with Git. See… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/418/">link</a></p><h4>Strategies for Securing Web Content</h4><p>Whether you use web content in your app via an embedded WebKit view, deliver pure web apps, or create web content to be embedded by others, it’s important to ensure that you are using the most current web security standards. Learn techniques like such as special cookie attributes and HTTP… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/207/">link</a></p><h4>Swift Generics</h4><p>Generics are one of the most powerful features of Swift, enabling you to write flexible, reusable components while maintaining static type information. Learn about the design of Swift’s generics, including how to generalize protocols, leverage protocol inheritance to express the varying… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/406/">link</a></p><h4>Testing Tips &amp; Tricks</h4><p>Testing is an essential tool to consistently verify your code works correctly, but often your code has dependencies that are out of your control. Discover techniques for making hard-to-test code testable on Apple platforms using XCTest. Learn a variety of tips for writing higher-quality tests… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/417/">link</a></p><h4>TextKit Best Practices</h4><p>Leverage the abilities of TextKit to provide the best experience possible displaying and editing text. Get the best performance out of your app by using TextKit effectively. Learn the concepts to do more complex handling, layout and presentation. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/221/">link</a></p><h4>The Life of a Button</h4><p>An in-depth exploration of essential interaction, visual and sound design principles and techniques through the design of a simple button. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/804/">link</a></p><h4>The Qualities of Great Design</h4><p>Great Design isn’t magic, it is crafted with care by real people. Explore the characteristics of great design through the voices of designers from Apple and our developer community. Learn how they take inspiration from everyday life, conceive and refine ideas, and push themselves to design apps… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/801/">link</a></p><h4>UIKit: Apps for Every Size and Shape</h4><p>Ground-up coverage of how to make an app that can fit on devices of every size and shape. Make your app fit beautifully on Apple’s full range of devices with the minimum amount of effort, future-proofing your user experience along the way. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/235/">link</a></p><h4>Understanding ARKit Tracking and Detection</h4><p>With ARKit your app can see the world and place virtual objects on horizontal and vertical surfaces and recognize images and objects. Go beyond the API to gain insights into the innovative methods and techniques underlying these capabilities. See how ARKit combines device motion with the camera… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/610/">link</a></p><h4>Understanding Crashes and Crash Logs</h4><p>Sudden app crashes are a source of bad user experience and app review rejections. Learn how crash logs can be analyzed, what information they contain and how to diagnose the causes of crashes, including hard-to-reproduce memory corruptions and multithreading issues. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/414/">link</a></p><h4>Using Accelerate and simd</h4><p>Learn how to use sophisticated Signal and Image Processing techniques to bring higher performance to your apps while lowering battery consumption. See compelling use cases for the Accelerate framework with interactive demos. Explore using simd\u2014a valuable addition that effortlessly brings… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/701/">link</a></p><h4>Using Collections Effectively</h4><p>Every app uses collections! Go beyond the basics with specific tips on how best to use indices, slices, bridging, laziness, and reference types. Gain better understanding of when to use each collection for best performance. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/229/">link</a></p><h4>Using Grouped Notifications</h4><p>Grouping the notifications your app sends helps people get more information at a glance and manage multiple notifications at once. Learn how to implement Grouped Notifications in your app. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/711/">link</a></p><h4>Vision with Core ML</h4><p>Using Core ML models in Vision makes the creation of powerful Computer Vision applications easy. Learn how easy it is to use custom trained classifiers and object recognition models in a live camera capture. In addition, you’ll learn about the latest additions to the Vision Framework along with a… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/717/">link</a></p><h4>VoiceOver: App Testing Beyond The Visuals</h4><p>VoiceOver provides spoken descriptions and braille output of onscreen elements. Learn how to go beyond the visuals to identify VoiceOver and functional issues to help improve the experience for all users. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/226/">link</a></p><h4>WWDC 2018 Keynote</h4><p>WWDC 2018 Keynote <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/101/">link</a></p><h4>Wallet and Apple Pay: Creating Great Customer Experiences</h4><p>Get the latest news and updates from the Wallet and Apple Pay team. Learn how iPhone and Apple Watch can power innovative commerce experiences. Hear about the latest design best practices for Apple Pay. And discover how to create your own contactless passes for rewards cards, gift cards, tickets… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/720/">link</a></p><h4>What’s New in App Store Connect</h4><p>App Store Connect is constantly evolving to improve the experience of managing and deploying your app on App Store. Learn about the new App Store Connect API for managing frequently modified data such as users and groups, see the latest updates to Sales Trends and Analytics reporting, and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/301/">link</a></p><h4>What’s New in Cocoa Touch</h4><p>iOS 12 enhances the Cocoa Touch frameworks to improve app performance and deliver exciting new features. Learn about performance best practices, security improvements, tools for supporting multiple screen sizes and shapes, new APIs for iMessage apps, Siri Shortcuts, and Swift refinements. Find… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/202/">link</a></p><h4>What’s New in Cocoa for macOS</h4><p>Gain insights into the latest in Cocoa frameworks for macOS. Hear about Dark Mode, control tinting, contextual workflows for Touch Bar and Finder, and other improvements in AppKit, Foundation, and related areas. Get an overview and guide to the sessions that we have this year covering… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/209/">link</a></p><h4>What’s New in LLVM</h4><p>The LLVM suite of compiler tools in Xcode 10 have new language features, improved diagnostics, and more powerful optimizations. Find out about improvements to ARC for Objective-C, keep up with the newest additions to C++, get an overview of new and improved diagnostics and static analyzer checks,… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/409/">link</a></p><h4>What’s New in Managing Apple Devices</h4><p>Learn about new management capabilities for iOS, macOS, and tvOS, tool evolution over the past year, and important changes coming this fall. You’ll discover how new MDM features help administrators manage devices more effectively, how educators can enhance the classroom learning environment, and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/302/">link</a></p><h4>What’s New in Search Ads</h4><p>Search Ads is a great way to help people discover your app in App Store search results. Learn how new market expansion will give you greater opportunities to reach high quality customers. See how Search Ads Advanced new creative variations will help make your app promotion even more effective. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/304/">link</a></p><h4>What’s New in Swift</h4><p>Hear about the latest advancements in Swift, the safe, fast, and expressive language. Find out about improvements to build times, code size, and runtime performance. Learn how to take advantage of new features in your code that eliminate boilerplate, increase safety and security, and improve your… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/401/">link</a></p><h4>What’s New in TVMLKit</h4><p>With TVMLKit you can quickly and easily develop tvOS apps that deliver intuitive and engaging media experiences. Learn about enhancements to data binding that allow you to separate your application logic and user interface, and new features and functions to customize the media playback experience. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/238/">link</a></p><h4>What’s New in Testing</h4><p>Hear about exciting improvements to code coverage, including how you can build your own automation on top of Xcode’s coverage reports. Learn how to dramatically speed up the execution of your tests by leveraging distributed parallel testing, new in Xcode 10. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/403/">link</a></p><h4>What’s New in tvOS 12</h4><p>Apps on tvOS entertain, inform, and inspire with their content and interactive experiences. tvOS 12 brings new technologies that help make these experiences even more enjoyable and engaging. Get an introduction to focus engine support for non-UIKit apps, new UI elements, and Password AutoFill… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/208/">link</a></p><h4>What’s New in watchOS</h4><p>watchOS 5 makes creating great experiences on Apple Watch easier than ever before. Learn about robust capabilities to create rich and interactive notifications, a new background mode and controls for audio playback, shortcuts that bring your apps to the Siri watch face, and more. See what’s new… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/206/">link</a></p><h4>What\u2019s New in ARKit 2</h4><p>ARKit 2 makes it easy to develop vivid augmented reality experiences and enable apps to interact with the real world in entirely new ways. Discover how multiple iOS devices can simultaneously view an AR scene or play multiplayer AR games. Learn about new capabilities for tracking 2D images, and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/602/">link</a></p><h4>What\u2019s New in Core ML, Part 1</h4><p>Introduced just one year ago, Core ML has already revolutionized the way apps can benefit from machine learning, by enabling fast and private on device machine learning features for your app. Find out how new Core ML features let you reduce the size of models, make them more flexible, and… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/708/">link</a></p><h4>What\u2019s New in Core ML, Part 2</h4><p>The Core ML tools ecosystem gives you many options for building and optimizing models to meet your app requirements. Learn how to add flexibility to existing models, quantize them, and take advantage of Core ML’s support for customization. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/709/">link</a></p><h4>What\u2019s New in Energy Debugging</h4><p>People expect long battery life on their mobile devices, and apps play a vital role in achieving that experience. Understand how app behavior affects battery consumption, and learn strategies to conserve energy while providing the best experience for your app. Find out how Xcode Energy Reports… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/228/">link</a></p><h4>What\u2019s New in Safari and WebKit</h4><p>Safari and WebKit are continually evolving with new features, APIs, and cutting edge web standards. Learn about this year’s biggest feature highlights, designed to help you create richer experiences with better performance and security \u2014 whether you are developing content for a browser or… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/234/">link</a></p><h4>What\u2019s New in User Notifications</h4><p>Local and push notifications enable your app to keep users informed with timely and relevant content, by displaying messages and accepting users’ actions, or playing distinctive sounds, or updating the badge on your app icon. Improvements to rich notifications help you create more engaging… <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/710/">link</a></p><h4>Your Apps and the Future of macOS Security</h4><p>Apple is on a mission to advance the state of Mac security, and we want your apps to be there with us. Learn about new protections for user data, new capabilities with Developer ID, and how you can best secure your apps. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/702/">link</a></p><h4>iOS Memory Deep Dive</h4><p>Discover how memory graphs can be used to get a close up look at what is contributing to an app’s memory footprint. Understand the true memory cost of an image. Learn some tips and tricks for reducing the memory footprint of an app. <a href="https://developer.apple.com/videos/wwdc2018/videos/play/wwdc2018/416/">link</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ce1cdfd1053" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ios-nerd/wwdc-18-sessions-%E7%B8%BD%E8%A6%BD-8ce1cdfd1053">WWDC 18 Sessions 總覽</a> was originally published in <a href="https://medium.com/ios-nerd">iOS Nerd 🤓</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[斷言 Assertion]]></title>
            <link>https://medium.com/ios-nerd/%E6%96%B7%E8%A8%80-assertion-1c5f7c65d1b7?source=rss-455eede53a04------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c5f7c65d1b7</guid>
            <category><![CDATA[assertions]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Liyao Chen]]></dc:creator>
            <pubDate>Thu, 17 May 2018 02:59:32 GMT</pubDate>
            <atom:updated>2018-05-17T02:59:32.845Z</atom:updated>
            <content:encoded><![CDATA[<h4>錯誤處理之不要亂用我設計的物件</h4><p>錯誤是很抽象的字，廣義來說所有不在預期內的結果都算是某種”錯誤”。</p><p>接下來會分兩三篇文章來分享最近所學到跟錯誤處理相關的議題，話不多說我們開始吧💪</p><p>斷言(Assertion) 是一種條件式檢查語法，當現行狀態不合乎條件時會強迫終止程式。</p><blockquote>斷言只用在標示一些邏輯上不可能或不應該出現的情形，若上述情形真的出現時，表示有些基本架構已出現問題。 — <a href="https://zh.wikipedia.org/wiki/%E6%96%B7%E8%A8%80_(%E7%A8%8B%E5%BC%8F)">wiki 斷言</a></blockquote><h3>為什麼會需要斷言</h3><p>當程式碼執行到<strong>不該出現的狀</strong>態時，且一但進入此狀態就執行不下去的時候。常用在<strong>提醒開發者</strong> API 的使用規範、此程式碼缺少必要圖片、初始狀態資料缺少等等。</p><p>白話一點就是『這裡有嚴重錯誤，請你<strong>現在</strong>把程式碼修好』，舉例來說：</p><ul><li>汽車應該只能汽油，若是加了沙拉油就會讓車子受損，請不要亂加</li><li>初始值應該永遠都要存在，若不存在物件無法建立</li><li>必要圖片 (app icon) 一定要包含在資料夾裡</li><li>function 的輸入值規範在某個範圍 (分數 0–100)</li><li>虛擬類別的建立(Swift API 目前無法宣告虛擬類別)</li></ul><p>一段設計良好的程式碼應留下足夠的前後文相關線索，提醒使用者(Code user) 物件或方法的使用條件。但我們都知道沒有人喜歡看說明書 (Document)，所以更高明的做法就是直接用程式碼規範條件，並且在使用者犯規(不合乎規範)時提醒他，而斷言(Assertion)這個語法就是為此而生。</p><h3>Assert</h3><p>預設僅在 Debug 編譯下才會作用，在 Production 沒有效能影響。</p><blockquote>Use this function for internal sanity checks that are active during testing but do not impact performance of shipping code. — <a href="https://developer.apple.com/documentation/swift/1541112-assert">Apple Document</a></blockquote><p>接著我們來看一段規範輸入範圍的斷言範例</p><pre>// This method only works when score 0-100 (bounds)<br>func update(score: Int) {<br>  assert(score &gt;= 0, &quot;score should never be native value&quot;)<br>  assert(score &lt;= 100, &quot;score should never greater than 100&quot;)<br>  <br>  // Prevent crash <br>  let newScore = min(max(0,score), 100)<br>  print(newScore)<br>}</pre><p>你可以注意到這裡用 assert 來強制規範 score 必須介於 0 - 100 之間。除此之外，在程式碼後段的 min(max(0,score), 100) 則是用來將範圍外的資料修正，來避免在 production 環境下 Crash 。</p><h3>AssertionFailure</h3><p>不該執行到這一行，但是萬一 Production 執行到會忽略</p><pre>func testAsertionFailure() {<br>    assertionFailure(&quot;nope&quot;)<br>    println(&quot;ever&quot;) // never be executed when debug.<br>}<br><br>guard score &gt;= 0, score &lt;= 100 else {<br>  assertionFailure(&quot;score out of bounds.&quot;)<br>  // If out of bounds in production will be ignored.<br>  return<br>}<br><br>db.write(score: score)</pre><p>在上面這個範例裡，當數值超過範圍時不會寫入 db ，並且在 Config = DEBUG 時丟出 exception 。</p><h3>Precondition</h3><p>跟 Assert 很像但作用在 Debug 及 Release 。</p><pre>// This method only works in 0-100 (bounds)<br>func update(score: Int) {<br>  precondition(score &gt;= 0, &quot;score should never be native value&quot;)<br>  precondition(score &lt;= 100, &quot;score should never greater than 100&quot;)<br>  <br>  let newScore = min(max(0, score), 100) // never excute<br>  print(newScore)<br>}</pre><p>同樣的例子用 Precondition 的話 let newScore 這行就永遠不會被執行了，因為 Precondition 無論在 DEBUG 或 Release 都會生效。</p><h3>PreconditionFailure</h3><p>跟 FatalError() 一樣</p><pre>guard let config = loadConfig() else {<br>  preconditionFailure(&quot;Config couldn&#39;t be loaded. Verify that Config.json is Valid&quot;)<br>}<br><br>// fatal error: Config couldn’t be loaded. Verify that Config.json is valid.: file /Users/John/AmazingApp/Sources/AppDelegate.swift, line 17<br><br><br>// [Require] powered by Sundell<br>// https://github.com/JohnSundell/Require<br>let config = loadConfig().require(hint: &quot;Verify that Config.json is Valid&quot;)</pre><h3>FatalError</h3><p>當某些區塊不想別人存取時，可以使用 fatalError 來明示。（常用在抽象類別。）</p><p>fatalError 還有另一個特性，它可以無視 return 關鍵字，請看下面範例。</p><pre>// Abstract class<br>class Animal {<br>  func roar() {<br>    fatalError(&quot;Must override this method&quot;)<br>  }<br>}<br><br>class Cat: Animal {<br>  override func roar() {<br>    print(&quot;Meow!&quot;)<br>  }<br>}<br><br>enum MyEnum {<br>    case Value1,Value2,Value3<br>}<br><br>func check(someValue: MyEnum) -&gt; String {<br>    switch someValue {<br>    case .Value1:<br>        return &quot;OK&quot;<br>    case .Value2:<br>        return &quot;Maybe OK&quot;<br>    default:<br>        // 不加 return 也能編譯通過<br>        fatalError(&quot;Should not show!&quot;)<br>    }<br>}</pre><p>它表示不得不實作，但是做一個空實做時，並暗示它永遠不該被使用。</p><h3>小結</h3><p>Assertion 是很有用的東西，若是使用得當不僅能夠減少文件跟註解，也能讓後續使用的人能夠有明確指引，並且在超出原始設計的預期範圍能夠及時修正。</p><p>有沒有感覺更上一層樓了呢？一起持續學習吧 :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c5f7c65d1b7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ios-nerd/%E6%96%B7%E8%A8%80-assertion-1c5f7c65d1b7">斷言 Assertion</a> was originally published in <a href="https://medium.com/ios-nerd">iOS Nerd 🤓</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/honestbee-tw-engineer/%E9%87%8D%E6%A7%8B-%E9%87%8D%E7%8F%BE%E9%9A%B1%E8%97%8F%E7%9A%84%E4%BE%9D%E8%B3%B4%E9%97%9C%E4%BF%82-9c066d606d92?source=rss-455eede53a04------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c066d606d92</guid>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[testable]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <dc:creator><![CDATA[Liyao Chen]]></dc:creator>
            <pubDate>Mon, 26 Feb 2018 08:23:08 GMT</pubDate>
            <atom:updated>2018-04-16T14:25:16.164Z</atom:updated>
            <content:encoded><![CDATA[<h3>重構：消除隱藏的依賴關係</h3><p><strong>不可測試的程式碼</strong>就像是沒打掃的房間，可能玩具散落一地，又或是不穿的衣服堆得亂七八糟。</p><p>想像你的每一個類別(Class)就是房間，可能有的很小容易打掃，有的很大不容易保持乾淨。隨著你的產品(Project)房子愈來愈大，房間愈來愈多，要整理乾淨就愈難。很多人甚至就不打掃放任專案慢慢發臭，輕微一點導致 bug 開趴，嚴重一點則導致開發新功能困難舉步維艱。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UzuG5zR4ye8MYYEv." /><figcaption>Photo by <a href="https://unsplash.com/@ratushny?utm_source=medium&amp;utm_medium=referral">Dmitry Ratushny</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>今天讓我們來看看一個例子 HBBeePointUtilites，它是一個用來讀取點數暫存的物件，但因為所有 method 都是實作成 class method，所以讓這段程式碼難以測試，在這邊將示範如何用依賴注入(Dependency Injection) 將<strong>隱藏的依賴關係</strong>轉成<strong>顯著的依賴關係</strong>，藉此讓這段程式碼得以測試。</p><h4>隱藏在實作的外部依賴</h4><p>先來看看我們怎麼使用這個物件：</p><pre>// 從 class method `getPoint()` 取得點數 <br>let point = HBBeePointUtilites.getPoint()</pre><p>接著我們查看它的實作會發現這個物件有個外部依賴 UserDefaults.standard ，糟糕的是他是一個 singleton ，在不使用其他外部測試 framework 的情況下，我們無法換掉它，也就無法測試。</p><pre>// Before<br>class HBBeePointUtilites {<br>    class func getPoints() -&gt; Int {<br>        // 對 UserDefaults.standard 的依賴<br>        return UserDefaults.standard.integer(forKey: &quot;BeePoints&quot;)<br>    }<br>}</pre><p>從上面這段程式碼來看，你大概可以臆測到它是為了在專案全域都可以讀取點數才這樣設計，但是這樣的設計卻犧牲了程式碼的<strong>可測試性</strong>，在這樣的前提之下我們可以如何修改呢？</p><p><strong>先設定目標：</strong><br>1. 全域存取 <br>2. 可測試</p><p>在不破壞原功能的前提下，為這個物件增加可測試性。</p><h4>獨生子模式 Singleton pattern</h4><p>針對 <strong>目標1: 全域存取</strong> 其實不只是 class method 可以， singleton 也做的到：</p><pre>// before: class method<br>let oldPoint = HBBeePointUtilites.getPoint()<br><br>// after: singleton instance method<br>let newPoint = HBBeePointUtilites.shared.getPoint()</pre><p>如上面這段程式碼所示，兩段程式碼只差在.shared ，只不過一個是用 class method 另一個則是 singleton ，很容易相互取代。</p><h4>建構子依賴注入 DI</h4><p>而 <strong>目標2: 可測試</strong> 比較複雜，我們可以透過依賴注入將原先隱藏在其中的依賴UserDefaults.standard 暴露至建構子當中。</p><p>接著我們開一個 property userDefault 將原本直接使用 UserDefaults.standard 轉向在建構時對外要求一個 UserDefaults ：</p><pre>class HBBeePointUtilites {<br>    // 原本的 class function<br>    class func getPoints() -&gt; Int {<br>        return UserDefaults.standard.integer(forKey: &quot;BeePoints&quot;)<br>    }<br>    <br>    // 宣告 let 而不 assign 值，等建構子帶入<br>    // compiler 會幫你檢查<br>    private let userDefaults: UserDefaults<br>    <br>    // 建構子依賴注入<br>    init(userDefaults: UserDefaults) {<br>        self.userDefaults = userDefaults<br>    }<br>    <br>    // 複製 class function 的內容到 method，<br>    // 並改成依賴傳入的 `self.userDefaults`<br>    func getPoints() -&gt; Int {<br>        return self.userDefaults.integer(forKey: &quot;BeePoints&quot;)<br>    }<br>}</pre><p>這時候你已經可以測試了</p><pre>// Arrange <br>let fakeUserDefaults = UserDefaults(suiteName: “Test”)! fakeUserDefaults.set(1000, forKey: “BeePoints”) <br>let util = HBBeePointUtilites(userDefaults: fakeUserDefaults)</pre><pre>// Action <br>let result = util.getPoint() // 1000</pre><pre>// Assert <br>XCTAssert(result == 1000) // true</pre><p>確定程式碼得以測試以後，才將原本的 class method 移除，最後程式碼會是這樣：</p><pre>// Final<br>class HBBeePointUtilites {<br>    static let shared = HBBeePointUtilites(userDefaults: UserDefaults.standard)<br>    <br>    private let userDefaults: UserDefaults<br>    <br>    init(userDefaults: UserDefaults) {<br>        self.userDefaults = userDefaults<br>    }<br>    <br>    func getPoints() -&gt; Int {<br>        return self.userDefaults.integer(forKey: &quot;BeePoints&quot;)<br>    }<br>}</pre><h4>一次做一件事</h4><p>需要注意的是，一次替換太多 class method 可能導致出錯，萬一手殘就會前功盡棄。所以<strong>請一次替換一個 class method</strong>，並且每一次完成替換前加入測試，完成後才提交 commit 。</p><p>值得一提的是 singleton 這邊的小技巧，透過依賴注入但是預設注入 UserDefaults.standard:</p><pre>static let shared = HBBeePointUtilites(userDefaults: UserDefaults.standard)</pre><p>這樣在 Production 程式碼可以維持乾淨，像下面的程式碼這樣：</p><pre>let point = HBBeePointUtilites.shared.getPoint()</pre><p>太好了，現在這個物件可測試，我們對產品的信心又提升了一點！</p><p>讓我們回顧一下步驟：</p><ol><li>用建構子依賴注入暴露原本隱藏的依賴</li><li>用 singleton 模式讓方法全域存取</li><li>複製 class method 為 instance method</li><li>為新的 method 加入測試</li><li>移除舊的 class method</li></ol><p>(重複 3–5 步驟直到所有 method 都可測試，並且一次只換一個 method)</p><h4>結論</h4><p>若實作時沒考慮到<strong>單元測試</strong>，我們理所當然的會設計出<strong>不可測試的程式碼</strong>。但是已經髒亂的房間不代表可以不管，讓我們一起捲起袖子來大掃除。</p><p>在這次簡單的例子中我想大家都能深刻瞭解，若是平常不好好打掃，最後大掃除就很累 XD</p><p>所以，寫新的程式碼時請將<strong>可測試性</strong>考慮進去，因為愈早考慮可測試性，事情就越簡單。保持房間乾淨整齊，這樣下一個來使用的人(極有可能是3個月後的自己)才會容易根據<strong>需求</strong>更改房間擺設。</p><p>我是 honestbee 的 iOS 工程師 Liyao Chen 我們下次見！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c066d606d92" width="1" height="1" alt=""><hr><p><a href="https://medium.com/honestbee-tw-engineer/%E9%87%8D%E6%A7%8B-%E9%87%8D%E7%8F%BE%E9%9A%B1%E8%97%8F%E7%9A%84%E4%BE%9D%E8%B3%B4%E9%97%9C%E4%BF%82-9c066d606d92">重構-重現隱藏的依賴關係</a> was originally published in <a href="https://medium.com/honestbee-tw-engineer">honestbee-tw-engineering</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/@gliyao/%E6%8B%9B%E5%8B%9F%E8%88%87%E8%A2%AB%E6%8B%9B%E5%8B%9F-36aa33da9438?source=rss-455eede53a04------2</link>
            <guid isPermaLink="false">https://medium.com/p/36aa33da9438</guid>
            <category><![CDATA[recruit]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Liyao Chen]]></dc:creator>
            <pubDate>Fri, 26 Jan 2018 04:49:13 GMT</pubDate>
            <atom:updated>2018-01-31T14:07:19.412Z</atom:updated>
            <content:encoded><![CDATA[<h4>你在面試公司，公司也在面試你。</h4><p>招募的核心是在<strong><em>有限時間內評估面試者是否適合加入團隊</em></strong>，也就是要先能認識面試者才能評估他是否合適。</p><p>首先我們必須認清一個事實，要在短短一兩個小時內瞭解一個人基本上是不可能的，所以面試前的情報收集就格外重要。能收集到愈多關於面試者的資訊，就能愈瞭解該面試者，反之收集資料愈少就是愈只依賴面試者提供給你的資訊。關於面試表面上的流程是準備履歷、投履歷、面試，但其實面試早在你投履歷之前就開始了，怎麼說呢？</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wciHOpeLGCZkL6gX6_Ti-w.jpeg" /><figcaption>象徵 KKTWON 的黃色旗幟</figcaption></figure><p>我們是如何形容一個人呢？比如說我們形容 NBA 球星 Curry 是神射手，是如何歸納出來的呢？ 是由他比賽中的表現來累積大家對他的印象，不科學的的三分投射距離，關鍵時刻的精準三分投籃，整體三分投籃數量及進球比例。</p><p>也就是說由<strong>過去做過的事情</strong>去定義他是怎麼樣的人。</p><p>那我們在認識(被認識)的過程中又展現了什麼呢？如果面試者自述對單元測試很有興趣，但卻說不出他讀過哪一篇文章，或是知道其中任一概念，也沒有在網路上發表任何關於單元測試的言論，那我們是否該取信於他呢？</p><p><strong>人會說謊但是行為不會</strong>，所以我們不能只看他說了什麼，而是去觀察他<strong>做過什麼</strong>。</p><p>這也就是為什麼面試是一門與設計相關的藝術，你<em>必須</em><strong><em>透過問題設計與觀察去洞悉面試者背後的意圖</em></strong>，而不是直接問他你想知道的答案。</p><h3><strong>招募</strong></h3><p>你渴望與什麼樣特質的人工作？<br>自己是否具備這樣的特質？</p><h4>必備</h4><ul><li>誠實</li><li>願意承認錯誤</li><li>團隊合作的觀念</li><li>軟體開發有熱情</li><li>會主動學習且樂於分享</li></ul><h4>加分</h4><ul><li>目前的程式能力</li><li>對於軟體品質的要求</li></ul><p>這些特質是我個人認為重要的特質，也是我反思自己是否具備這樣的特質，還有如何具備這樣的能力。</p><h4>透過問題設計來洞察人心</h4><ol><li><strong>誠實</strong> 與 <strong>願意承認錯誤 </strong>(知之為知之，不知為不知)：<br>a. 前一天晚上做了什麼？ 最近下班時間都在做什麼？ (避免已經準備好的答案，讓受測者放鬆)<br>b. 問一個較艱深的 iOS 開發問題，觀察受試者的反應，當遇到不懂的事情是否會硬凹。<br>c. 當不懂裝懂時被糾正的態度 (有無被動的學習能力)</li><li>團隊合作的觀念：<br>a. 過去的有無團隊合作經驗，你們如何合作？<br>b. 與團隊成員持不同意見時，你會怎麼做？ 有過這樣的經驗嗎？</li><li>軟體開發熱情 與 會主動學習且樂於分享：<br>a. 覺得自己現在的程式能力如何？目前如何持續學習？<br>b. 是否有分享經驗(blog, talk)？有或沒有的原因是什麼？<br>c. 過去做過的專案中遇過的挑戰，你如何克服它</li><li>目前的程式能力：<br>a. 設計模式(Design Pattern) 有印象的是哪些？<br>b. 單元測試(Unit Testing) 有多少瞭解？ 為什麼單元測試重要？<br>c. 如何衡量自己的軟體品質好不好？<br>d. 持續整合(Continuous Integration) 是什麼？重不重要，為什麼？</li><li>判斷是非及勇於堅持的問題：<br>a. 問一個不合理的問題，並看他面對不同答案時的表現。</li></ol><h4>準備功課</h4><ol><li>Resume： 面試者精選的資訊，但有可能<strong>造假</strong></li><li>網路資料：Github, Blog, Slide share, Google, Facebook, Instagram, twitter。這些情報來瞭解受試者 是否具備我們要的特質，這可以用實例來找 Pattern</li><li>On-site Interview：事前設計題目</li></ol><h4>評估分析</h4><ol><li>綜合 Resume + 面試提問來給出一個客觀的分數</li><li>再依照面試官個人感覺給出一個主觀分數</li><li>綜合客觀與主觀分數為最後分數。</li></ol><h3>面試</h3><p>思考過招募這端的目標後，準備面試的就變得有方向</p><p>你現在是否具備上述好的特質？你將如何準備這些特質？</p><ul><li>透過撰寫個人 Blog 分享所學技術，也練習思考與文筆</li><li>與朋友組織課後讀書會，研讀技術相關的文章或書籍</li><li>透過參加社群認識好的工程師，並向他們學習</li></ul><p>如何瞭解一間公司的文化？</p><ul><li>有沒有認識的人在裡面工作，詢問他對公司文化的看法</li><li>透過網路搜尋該公司相關資訊，看公司對技術的重視程度</li><li>準備一些瞭解公司文化的問題面試時提問</li></ul><h4>心態</h4><p>不同公司文化不同，有時沒錄取不見得是壞事，只是當下雙方沒達成一定的共識。 有時只是緣份未到剛好面試官跟你的氣味不相投，所以這次沒機會合作。</p><p>面試整體過程保持禮貌，這次沒談成不見得以後沒有合作機會，可能是公司再度擴編，又或者你的能力提升到符合公司的需求。</p><h4>持續關注好公司</h4><p>自己對於好公司的定義是什麼？ 薪資福利？ 未來發展性？ <br>現階段已經具備什麼能力？<br>現階段自己缺少什麼能力？</p><h4>薪資談判</h4><p>將自己的特質與能力攤在桌面上，讓公司評估用多少資源來招攬你。<br>心態保持健康，即使該公司的 Offer 不如你的預期，也可以禮貌性的請招募人員試著幫忙爭取更好的待遇 ，如果你帶來的價值符合更好的 Offer ，相信招募人員也會很願意幫你爭取看看，無論結果如何都感謝對方的幫忙。</p><h4>履歷</h4><p>是面試官對你的第一印象，儘可能精選出最有價值的部分。 精選的要領就在於少，即時。</p><p>儘可能以 問題→ 行動 → 結果 的方式敘述來幫助面試官瞭解你的故事。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36aa33da9438" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[實作 UIStack — 讓 UI 不再出錯]]></title>
            <link>https://medium.com/@gliyao/%E5%AF%A6%E4%BD%9C-uistack-%E8%AE%93-ui-%E4%B8%8D%E5%86%8D%E5%87%BA%E9%8C%AF-8be9b2f5925e?source=rss-455eede53a04------2</link>
            <guid isPermaLink="false">https://medium.com/p/8be9b2f5925e</guid>
            <category><![CDATA[state-machine]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Liyao Chen]]></dc:creator>
            <pubDate>Mon, 08 Jan 2018 13:55:51 GMT</pubDate>
            <atom:updated>2018-01-08T13:56:40.384Z</atom:updated>
            <content:encoded><![CDATA[<p>你是否也曾因為一在發生的 UI 錯誤煩惱？ 當 QA 又 回報某個頁面錯誤，[Bug] 精選頁面 Load more 未顯示 Loading indicator，為什麼要說又呢？</p><p>如果你也有這樣的症頭，請繼續看下去。</p><figure><img alt="為什麼要說又呢" src="https://cdn-images-1.medium.com/max/512/0*prq2XNcTlRylauiu.jpg" /><figcaption>為什麼要說又呢</figcaption></figure><p>雖然我們依循 <a href="https://zh.wikipedia.org/wiki/MVC">Model-View-Controller(MVC)</a> 的架構開發，但對於複雜的 UI 狀態改變還是會出錯。</p><p>哪裡處了問題？</p><pre>Class KKFeaturedViewController: UIViewController {<br>    var cards: [Card]<br>    var isLoading: Bool<br>    var isReloading: Bool<br>    var hasMore: Bool<br>    var loaded: Bool<br>    // ...<br>}</pre><p>大家都寫得差不多，建立多個 flag 來判斷不同的狀態，這樣的程式碼哪裡有問題？ 讓我們回到 QA 回報的問題 [Bug] 精選頁面 Load more 未顯示 Loading indicator ，可以從上面的變數中推測當 Load more 時，會是什麼狀態？</p><ol><li>cards.count &gt; 0</li><li>isLoading == true</li><li>isReloading == false</li><li>hasMore == false || true</li><li>loaded == true</li></ol><p>由下列程式碼中很清楚的光是 cards.count 跟 hasMore 就定義了四種狀態。更不用說在此架構下若要滴水不漏，你需要處理 2 的 4 次方，也就是 16 種狀態。</p><pre>Class KKFeaturedViewController: UIViewController {<br>    // ...<br>    <br>    func fetchCardAPI() {<br>        // ...<br>        isLoading = true<br>        if hasMore {<br>            if cards.count == 0 {<br>                // First load without content (reload)<br>            }<br>            else {<br>                // Loading more with content (load more)<br>            }<br>        }<br>        else {<br>            if cards.count == 0 {<br>                // Empty content<br>            }<br>            else {<br>                // Content complete<br>            }<br>        }<br>    }<br>}</pre><p><strong>不存在狀態</strong> if (loaded == false &amp;&amp; cards.count &gt; 0) { // 不該存在的狀態 }</p><p>16 個狀態組合中若不小心出現了不該出現的狀態，Bug 就產生了。同時而且這樣的程式碼不容易分辨哪些狀態有處理過，哪些沒有，像是複雜的電路板到處接來接去，出錯時不容易找到問題出在哪，當然也就不容易修正。</p><figure><img alt="複雜的程式碼流程就像亂接的電路板" src="https://cdn-images-1.medium.com/max/721/0*9qN2je4eocPxLddu.jpg" /><figcaption>複雜的程式碼流程就像亂接的電路板</figcaption></figure><p>我想<a href="https://zh.wikipedia.org/wiki/%E6%9C%89%E9%99%90%E7%8A%B6%E6%80%81%E6%9C%BA">有限狀態機</a> 可以幫我解決這個問題。有限狀態機的概念是 在有線個數的狀態裡，狀態之間轉移的數學模型。 主要的元素有 狀態, 動作(事件) 來延伸出 狀態A + 事件 =&gt; 狀態B 。最常見的應用是交通燈(紅綠燈)，也就是 綠燈時 + 60秒 =&gt; 黃燈 以此類推。</p><p>回過頭來整理真正會出現的狀態，原本 16 種狀態只有成 8 種會出現，一半以上的狀態都可以忽略 (難怪這麼多 Bug )</p><p>參考<a href="http://scotthurff.com/posts/why-your-user-interface-is-awkward-youre-ignoring-the-ui-stack">How to fix a bad user interface</a>一文中並實作其 UI Stack 的概念。</p><figure><img alt="UI Stack" src="https://cdn-images-1.medium.com/max/1024/0*IgqAm-74SV_XRYrL.jpg" /><figcaption>UI Stack</figcaption></figure><h4>狀態實作</h4><p>在我們情境下需要考慮到較多的狀態，所以就從原本的 5 種延伸成下列 8 種(請你視使用情境而自行調整成需要的狀態)。</p><p>將 ViewController 的權責從 處理狀態轉換 + 過濾不必要的狀態 + 各個子UI管理 被簡化成 根據狀態顯示UI，並且集中管理。</p><pre>enum UIStack {<br>    // Blank State<br>    case initial // 初始狀態尚未開始載入資料</pre><pre>    // Loading State<br>    case initialLoading // 初始載入，可與 Reload 共用<br>    case partialWithLoading // 載入部分資料，但又觸發載入下一頁</pre><pre>    // Partial State<br>    case partial //載入部分資料<br>    case partialWithError //載入部分資料，但載入新資料過程有誤</pre><pre>    // Error State<br>    case error // 錯誤</pre><pre>    // Ideal State<br>    case perfect // 資料完整載入<br>    case empty // 打過 API 但是沒有資料 (empty inbox 的概念)<br>}<br><br>Class ListViewController: UIViewController {<br>    internal var state: UIStack = .initial {<br>        didSet {<br>            // * switch cases ... * //<br>        }<br>    }<br>}</pre><h4>總結</h4><p>把設定狀態 跟 顯示UI 的邏輯分離後會讓事情簡單很多，防止自己粗心大意。</p><h4>開發加速</h4><p>開發過程中可隨時模擬狀態，就連部分載入但有錯誤的情境都可輕易重現。 舉例來說，想要重現 contentEmpty 這個狀態，在以前我可能要去修改 API Clint 去偽裝這隻 API 回應給我 0 個資料，而現在只要直接改 state 即可。</p><h4>容易除錯</h4><p>當 UI 出錯時就可以分成兩種錯誤，一種是狀態錯了，另一種是對應的 UI 錯了。</p><h4>程式碼集中</h4><p>跟狀態相關的程式碼會集中在一個地方，統一實作。</p><h4>防呆</h4><p>狀態一但被定義，Swift 的 Switch case 會強迫你要實作所有 cases，不讓我們有偷懶的機會。</p><h4>Reference</h4><ul><li><a href="https://academy.realm.io/posts/sommer-panage-writing-your-ui-swiftly/">Writing Your UI Swiftly — Sommer Panage</a></li><li><a href="https://www.slideshare.net/zonble/switchcase-79451124">使用 switch/case 重構程式碼 — Zonble</a></li><li><a href="http://scotthurff.com/posts/why-your-user-interface-is-awkward-youre-ignoring-the-ui-stack">How to fix a bad user interface</a></li><li><a href="https://medium.com/@zonble/%E7%BF%BB%E8%AD%AF-%E5%A6%82%E4%BD%95%E4%BF%AE%E6%AD%A3%E5%A3%9E-ui-2f972da15d5b">翻譯-如何修正壞UI — Zonble</a></li><li><a href="http://gliyao.logdown.com/posts/2013/09/26/finite-state-machine-state-pattern">有限狀態機與狀態模式 — Liyao</a></li><li><a href="https://zh.wikipedia.org/wiki/%E6%9C%89%E9%99%90%E7%8A%B6%E6%80%81%E6%9C%BA">有限狀態機 — Wiki</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8be9b2f5925e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>