<?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 Spock 薛 on Medium]]></title>
        <description><![CDATA[Stories by Spock 薛 on Medium]]></description>
        <link>https://medium.com/@spock.hsu?source=rss-e55ade4a40a3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Vv9e-uCuQXNUYRwtfHYLLg.jpeg</url>
            <title>Stories by Spock 薛 on Medium</title>
            <link>https://medium.com/@spock.hsu?source=rss-e55ade4a40a3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 22:53:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@spock.hsu/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[如何構建一個 AWS CodePipeline 並結合 Aws Lambda services]]></title>
            <link>https://medium.com/@spock.hsu/%E5%A6%82%E4%BD%95%E6%A7%8B%E5%BB%BA%E4%B8%80%E5%80%8B-aws-codepipeline-%E4%B8%A6%E7%B5%90%E5%90%88-aws-lambda-services-f0a51ede2f07?source=rss-e55ade4a40a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0a51ede2f07</guid>
            <category><![CDATA[codepipeline]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Spock 薛]]></dc:creator>
            <pubDate>Thu, 16 Jan 2020 13:57:14 GMT</pubDate>
            <atom:updated>2020-01-16T14:00:14.357Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/570/0*vuyq_rIf7n7OPLCS.png" /></figure><p>使用 AWS CodePipeline 將 API 持續集成和部署到 AWS Lambda 的指南</p><h4>介紹</h4><p><strong>本文章的目標:<br></strong> * Aws Pipeline 介紹和部署</p><h4>Pipeline Overview</h4><p><strong>運作方式:</strong></p><p>Pipeline 由一系列的階段 (建置、測試和部署) 組成，在 CI / CD 中扮演邏輯部門的角色。每個階段由一系列的動作組成，像是建置程式碼或部署測試環境等工作，當一切順利才能進行到 Prod 階段。<br>同時，可透過 samTemplate 和 buildspec file 在部署 pipeline 同時，建立 Aws lambda services。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6q8ODJ97no53hLk5.png" /></figure><h4>Create AWS CodePipeline</h4><p>登入到 Aws 並進入 CodePipeline service，創建一個新的 pipeline</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-T3WCInElHcvohRc.png" /></figure><p>這邊需要填入 pipeline name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M2S9h8q5vlpc95YX.png" /></figure><p>接下來，需要添加 source 來源，這邊選擇 CodeCommit (也可使用 GitHub)，同時設定 branch name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SaVAuk-uYXlnxCzH.png" /></figure><p>然後，我們需要添加一個 build stage。選擇 AWS CodeBuild 作為構建提供者，接著 click create project。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w8gM5YXL75AEuRvq.png" /></figure><p>deploy stage 這邊可以先跳過，稍後在進行設定。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W_hXHPagXXKw0IJ0.png" /></figure><p>click create pipeline</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/0*32Ya-8VqvGU-uZvV.png" /></figure><p>沒什麼意外的話，最後會看到這個畫面，基本上已經建構完成，但別開心太早，現在才開始準備進行每個階段的設定。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Si1Jyye3wnmmKOja.png" /></figure><h4>Edit CodePipeline</h4><p>選擇 edit 來進行 pipeline 的設定。<br>每個 stage name 沒有固定，可以自行定義，但內容有一定順序。</p><p><strong>Source stage :<em><br></em></strong>這個階段基本上就是偵測指定的 branch 是否有任何 push 更新，並且產生 output artifacts 讓後面的 stage 使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*Pu_vqjlf4ug4s2UJ.png" /></figure><p><strong>Build stage:</strong><br>這個階段會 input 剛剛 source 產生的 artifact 並搭配一開始 create pipeline 時設定的 codeBuild(spockTest)。可以重新 create build project 或是從 Aws CodeBuild services 搜尋剛剛設定的 project 來進行修改，接著設定 output artifact name。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Iq0qxNWTfUznl-L3.png" /></figure><p>特別注意的是，CodeBuild 裡面的 buildspec 必須要搭配 code 裡的 buildspec file (ex:buildspecBeta, buildspecPP…)</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p><strong>Staging stage:</strong><br>此階段要設定的比較多，設定完 Action name 並將 Action provide 選擇 CloudFormation 後，需要去 CloudFormation -&gt; Create a new stack and change set，並將 samTemplate file 透過 Aws S3 讓 stack 拿到。</p><p>而 samTemplate file 裡面定義了 API 方法(GET, POST…) 和 Aws lambda function，也就是說 CloudFormation 會透過 S3 拿到的 samTemplate 在每次 pipeline 執行時，動態更新 lambda function 內容。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uR7pcXnPoS0l_J3C.png" /></figure><p>samTemplate 內容大致上會長這樣，Resources 下就是將建立的 lambda function name。Events 可以依據 API 有的方法加入 (ex: GET, DELETE..)</p><pre>AWSTemplateFormatVersion: ‘2010–09–09’<br>Transform: AWS::Serverless-2016–10–31<br>Description: spockTest <br>Resources:<br> spockTest:<br> Type: ‘AWS::Serverless::Function’<br> Properties:<br> FunctionName: spockTest<br> AutoPublishAlias: beta<br> Handler: src/handlers/app.handler <br> Runtime: nodejs10.x<br> CodeUri: .<br> Description: spockTest<br> MemorySize: 128<br> Timeout: 30<br> Role: ‘your role’<br> Events:<br> ApiPOST:<br> Type: Api<br> Properties: <br> Path: ‘/v1/spockTestApi’<br> Method: POST<br> RestApiId: !Ref spockTestAPI</pre><p>因篇幅的關係，這邊就不詳細介紹 CloudFormation 和 S3，有興趣的人可以自行前往 Aws <a href="https://aws.amazon.com/tw/cloudformation/features/">官網</a>瞭解。</p><p>CloudFormation 運作方式：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E20MvW9mkbdWhmif.png" /></figure><p><strong>Beta stage:</strong><br>終於到了部署的階段，這邊我們命名為 Beta stage。 Action provider 一樣選擇 CloudFormation ，stack 則選上一個階段建立的就行。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PHNW6tovqzR3CHpJ.png" /></figure><p>沒什麼意外的話，當 branch 有任何的變動 (也可以手動觸發)，就會觸發 pipeline 進行部署，並告知成功或失敗。pipline 部署成功後，可以去 Aws lambda 查看 function 是否成功被建立。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aQT_DBsQKK37fu94.png" /></figure><p>通常，正式的專案，會由 Beta -&gt; PP -&gt; Prod 一路測試和發佈 (名字或階段數量看各專案略有不同)。並透過每個階段的 pipeline 進行測試和階段部署來達到自動化部署測試的目的。當任何階段出問題時，可以輕鬆的 rollback 和檢查錯誤。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mwhDQATSxiKU13sS.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lvHBTZNu6b7ONP2x.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*elIfufmltE_9M77y.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*et4_ZkudUFY9p0K3.png" /></figure><h4>結論</h4><p>AWS 還提供了許多其他完整的服務，更詳細的說明可以參考 AWS 提供的文件。</p><p>希望這對您有幫助，本文中許多地方未特別說明，如有任何問題，請告訴我，或是參考 AWS 提供的說明。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0a51ede2f07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unit Test for Node.js | JEST]]></title>
            <link>https://medium.com/@spock.hsu/unit-test-for-node-js-jest-d03c256ef505?source=rss-e55ade4a40a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d03c256ef505</guid>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[Spock 薛]]></dc:creator>
            <pubDate>Sun, 06 Oct 2019 10:53:39 GMT</pubDate>
            <atom:updated>2019-10-06T10:53:39.408Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RRRGKoVjw9uKtWNdofCFMg.jpeg" /></figure><h3><em>前言｜</em></h3><p>通常來說，在每個程式語言裡，攻城獅每修改一次程式最少會進行一次單元測試，已證實達到工作目標，沒有程式錯誤。對後端來說，尤其重要！ code review 同事發的 pr 第一件事就是跑測試，確定沒有將原本的東西改壞。而MOCK 在 Unit Test 中尤其重要，無論是前端或是後端，我們常常需要製造某個替身 (Mock) 來模擬某個 function , db , Framework, Request ….</p><h3>How to write the Unit Test?</h3><p>熟悉 iOS 的人可能會馬上聯想到 XCTest, 而基於 Node.js 的後端來說，最常使用的其中一個 framework 就是 JEST，對於大多數得 JS 專案都可以直接使用，且可以快速的執行。</p><h3>Introduction JEST</h3><p><a href="https://github.com/facebook/jest">GitHub - facebook/jest: Delightful JavaScript Testing.</a></p><p><a href="https://jestjs.io/docs/en/getting-started">https://jestjs.io/docs/en/getting-started</a></p><p>大家就自己進去看看文件，應該是沒什麼問題的！ 有問題就 Google 一下</p><h3>Real Case</h3><p>看完了詳細的文件和介紹後，來看一下實際上可以怎樣使用吧：</p><p><strong>1. Mock framework</strong></p><p>通常，我們在開發時，會使用許多的第三方服務 framework, 像是 AWS S3。想當然，我們必須 Mock S3 來測試程式邏輯是否正常。</p><p>使用JEST 建立一個 Mock，最基本的方式就是jest.fn() ，同時搭配 <strong>mockImplementation </strong>或 <strong>mockReturnValue</strong> 來定義回傳值。</p><pre>const mockFunction = jest.fn().mockImplementation(() =&gt; {<br> return &#39;YAA&#39;<br>})</pre><pre>constMockFunction2 = jest.fn().mockReturnValue(true)</pre><pre>console.log(mockFunction()) // 回傳 YAA<br>console.log(constMockFunction2()) // 回傳 true</pre><p>現在，回到 Mock AWS S3 部分，我們可以這樣做：</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8a09244d87c755c56d711064afb2ea5/href">https://medium.com/media/d8a09244d87c755c56d711064afb2ea5/href</a></iframe><p>特別注意的是，這邊 return 了另一個 function putObject(), 是因為在程式邏輯裡呼叫了 S3 裡的 putObject 方法。</p><p><strong>2. Mock Request</strong></p><p>基於 node-fetch 進行 API Request 的 Unit Test 就必須將整個 node-fetch Mock 起來，並且自訂回傳內容。並不是真的發送 Request 出去喔! 搭配 JEST 提供的方法，我們可以輕鬆的辦到。</p><pre>Jest.mock(‘framework’) // 接下來只要有用到該 framework 都被 Mock </pre><pre>const yourMock = require(&#39;framework&#39;) // 存到變數可以很清楚的進行接下來的處理</pre><pre>yourMock.mockImplementation (async () =&gt; {<br>  return logic ....<br>})</pre><p>對於 Request 的 Mock，不外乎就是成功跟失敗回傳的內容，假設測試必須同時參雜著 success, fail , success, success…. 的各種邏輯狀況，使用 <strong>mockImplementation</strong> 並不能應付這樣的改變。</p><p>其中一種做法是，可以使用 JEST 提供的另一種方法：</p><pre>mockImplementationOnce // 只會被呼叫一次</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8a09244d87c755c56d711064afb2ea5/href">https://medium.com/media/d8a09244d87c755c56d711064afb2ea5/href</a></iframe><p>可以搭配 Request 程式邏輯，來模擬不同的回傳內容，達到測試效果。</p><h3>結論|</h3><p>事實上，使用 JEST 進行 Unit Test 還有許多東西是這邊沒提到的，而主要精神莫過於透過 Unit Test 來確保程式品質和邏輯是否正確。</p><p>所以不要問同事 Unit 要怎寫，而是要問自己程式的邏輯怎寫的，進一步的透過 Unit Test 來測試。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d03c256ef505" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[創造自己的 CocoaPods library 並搭配 Travis CI]]></title>
            <link>https://medium.com/@spock.hsu/%E5%89%B5%E9%80%A0%E8%87%AA%E5%B7%B1%E7%9A%84-cocoapods-library-%E4%B8%A6%E6%90%AD%E9%85%8D-travis-ci-2979099fbfb?source=rss-e55ade4a40a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2979099fbfb</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Spock 薛]]></dc:creator>
            <pubDate>Sun, 26 May 2019 02:46:18 GMT</pubDate>
            <atom:updated>2019-05-26T03:52:53.468Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9zJ4sw6mW391Y7d5-UcIIQ.jpeg" /></figure><h3>創造自己的 CocoaPods library 並搭配Travis CI</h3><p>作為 iOS 開發人員，一定聽過 CocoaPods ，並非常熟悉如何安裝和使用。是否也想發表自己的 pod 來為 iOS 開源社群做出貢獻？</p><p>本文章內容包含，如何發布一個簡單的 pod，以及透過 Travis CI 確保 pod 的可靠度。</p><p>將手把手的介紹發布 pod 的九個步驟：</p><p><strong>1. Set up Xcode project</strong></p><p><strong>2. Link to GitHub</strong></p><p><strong>3. Implement the pod</strong></p><p><strong>4. Write unit tests</strong></p><p><strong>5. Configure Travis CI</strong></p><p><strong>6. What’s Trunk</strong></p><p><strong>7. Setting Up Podspec</strong></p><p><strong>8. Setting Up Trunk</strong></p><p><strong>9. Publish the pod</strong></p><h4>1.設置 Xcode 項目</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wa-eOQRc1DNY0SKIHYXSWw.png" /></figure><blockquote>CocoaPods library = Cocoa Touch framework</blockquote><p>這邊解釋一下 Framework 和 Static Library 的差別：</p><p><strong>Library </strong>裡面只能包含編譯完成的.a檔，可以直接執行。</p><p><strong>Framework </strong>則比較像是一群資源打包之後的結果，裡面會包含原始碼，header，圖片，nib，說明文檔等等...但必須仰賴外部環境，如果環境不正確或版本不對，就會出現找不到框架的錯誤，找不到的時候，就會崩潰。例如Foundation.framework 或 UIKit.framework 都是 Cocoa Touch 框架所提供的框架。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*i0sMch3ut4rcNUWc7FeHeQ.png" /><figcaption>兩個目標</figcaption></figure><blockquote>LittleSpock：實作 pod 的地方</blockquote><blockquote>LittleSpockTests：用來寫測試</blockquote><h4><strong>2. Link to GitHub</strong></h4><p>使用 GitHub 你懂的</p><h4><strong>3. Implement the pod</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*otfknMRnI8CPRWAxrBMyRA.png" /></figure><blockquote>在 project target 中新增 swift file，並將功能寫在裡面。</blockquote><h4><strong>4. Write unit test</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*9RVn1GnGsB6RvpHcMLZlUA.png" /></figure><blockquote>新增 Test case。</blockquote><h4><strong>5. Configure Travis CI</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*JK1AkQPX3KgXstodpsBp2Q.png" /></figure><blockquote>Travis CI 是一種託管的分佈式持續集成服務，用於建構和測試在 GitHub 上託管的專案項目</blockquote><p>Travis Ci 提供的是持續集成服務 (Continuous Integration ) 簡稱 CI ，他綁定 GitHub 上面的項目，只要有新的 code push 就會自動抓取，透過腳本提供一個運行環境，執行測試。</p><p>持續集成 CI 的好處在於：每次 code 的小幅度變更，就能看到運行結果，確保每次更動都是正確的。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*vz2mBvRkx1w10LCMCsf_Qg.png" /></figure><p>為了讓 Travis 獲取我們的 GitHub 中任何的更改，需在 Travis 上同步我們的 GitHub 帳戶並啟用我們的 repository。</p><blockquote>公開 Repository 到 <a href="https://travis-ci.org/">https://travis-ci.org</a></blockquote><blockquote>私人 Repository 到 <a href="https://travis-ci.com/">https://travis-ci.com</a></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bd3a90e76d12e5c3dfb0db4488d2479/href">https://medium.com/media/7bd3a90e76d12e5c3dfb0db4488d2479/href</a></iframe><blockquote>在專案目錄底下新增 .travis.yml file，並輸入欲執行腳本</blockquote><p>基本上，腳本內容為告訴 Travis 在兩個不同設備上運行單元測試 (XR / 7)，當然，可以自行增加預測試的機型，唯一要注意的是，有些 iOS 版本模擬器並不支援。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mt1cHnsdxFs8DvKRtYrvEA.png" /><figcaption>運行腳本中</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QFCzzzfmfn65jvLTRBAxlw.png" /><figcaption>通過測試</figcaption></figure><p>如果一切順利，每一次 commit 完，push 到 Github 的同時， Travis 就會自動執行腳本來測試，並且包含 commit 的完整資訊，可以知道是在哪邊出了問題。</p><p>恭喜，到這邊基本上 Travis 已經設定完成了，準備進入 push pod 的前置作業。</p><h4><strong>6. What’s Trunk</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0DMwe0Xar-enfrhOxtV3gA.jpeg" /><figcaption>圖片來源 <a href="https://cocoapods.org/">https://cocoapods.org/</a></figcaption></figure><blockquote>Trunk = 樹幹</blockquote><p>在 Trunk 推出來之前，如果要發布一個 CocoaPods 必須繁雜的透過 GitHub 操作才能完成，非常的麻煩。後來在 2014 年 5 月， CocoaPods 團隊推出了新的方法 “Trunk Web-service”。</p><p>第一個發布 Pod 的人自動被指定為該 pod 的 “owner”， “owner” 可以根據需要添加其他 “master” (協助開發)，但只能由 owner 發布 pod 後續版本。同時，仍然是相同的 git repo on GitHub (https://github.com/CocoaPods/Specs) ，所以如果 Trunk 因任何原因失敗，開發者也不會受到影響。結構如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*AfKCHl2MRkMM8pc2ZF6Nvw.png" /><figcaption>圖片來源 <a href="https://cocoapods.org/">https://cocoapods.org/</a></figcaption></figure><h4>7. Setting Up Podspec</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25ce0963f321ebbdce5b48e0a378904f/href">https://medium.com/media/25ce0963f321ebbdce5b48e0a378904f/href</a></iframe><blockquote>在終端機輸入，用來創建 Podspec 文件 (專案目錄底下)</blockquote><p>沒有 Podspec ，framework 只不過是一堆文件。 Podspec 是定義實際 CocoaPod 的東西。包含了 pod 的名稱，版本和 Git 下載 URL…等等。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bee879f69dbeb03ac636d840873b4cf8/href">https://medium.com/media/bee879f69dbeb03ac636d840873b4cf8/href</a></iframe><p>1. Pod 基本訊息</p><p>s.ios.deployment_target =&gt; 支持的 pod 最低版本</p><p>s.requires_arc = true =&gt; 是否支持 ARC</p><p>2. Podspec 本質上是 CocoaPod 的時間快照，由版本號表示。更新 pod 時，您還需要更新 Podspec 的版本。</p><p>3. 所有 pod 都必須指定許可證。如果不這樣做，CocoaPods 會在您嘗試安裝pod 時發出警告，並且您將無法將其上傳到 CocoaPods trunk。可以在此[https://choosealicense.com/licenses/mit/](https://) 找到的 MIT 許可證存到 專案目錄底下並命名為 “LICENSE” (確保替換 year 和 full name)</p><p>4.指定有關您自己的信息，即 pod 作者。輸入您的姓名和電子郵件地址。</p><p>5.指定 pod 主頁的 URL，只需要復制 GutHub 專案網址上來就行。</p><p>6.將此 URL 替換為專案中的 Git下載 URL。通常，最好使用 HTTP 或 HTTPS以便其他用戶更容易使用。</p><p>7.如果你的 pod 有依賴到其他第三方 pod，也需加入。</p><p>8.其他開發者安裝 pod 時，並不會安裝所有文件，需要指定哪些文件需要被安裝。</p><p>9. Pod 中使用的 Swift 版本。</p><blockquote>接著推到 GitHub 上，要確保 Git tag 跟 pod version和source 的標籤是一致的，否則之後驗證會失敗。</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18310107d234fa440b4086866bc05ddf/href">https://medium.com/media/18310107d234fa440b4086866bc05ddf/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*7TJMpwWb75ct6aZc6mFTZw.png" /></figure><blockquote>設定完後，可以透過命令檢查 Podspec 語法或邏輯是否錯誤</blockquote><p>一切準備就緒，準備使用 Trunk 服務。</p><h4><strong>8. Setting Up Trunk</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfd30a3b6e63e2722dd5bbd800733aff/href">https://medium.com/media/dfd30a3b6e63e2722dd5bbd800733aff/href</a></iframe><blockquote>要使用 Trunk 前，還需要註冊</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dac669eaeb5ed6decc9fbe6ad5d4d1e/href">https://medium.com/media/1dac669eaeb5ed6decc9fbe6ad5d4d1e/href</a></iframe><blockquote>可以確認是否註冊成功：</blockquote><h4><strong>9. Publish the pod</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b371198acac35c2914e4ddcfa39147a2/href">https://medium.com/media/b371198acac35c2914e4ddcfa39147a2/href</a></iframe><blockquote>是時候發布了！</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*pr8DC8a6vTHSfR6a9-OPtQ.png" /></figure><blockquote>如過一切順利，會看到成功訊息</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb715809814aa8aaa176559bce43d8b1/href">https://medium.com/media/fb715809814aa8aaa176559bce43d8b1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqawXE-0biBzcBxlvuP8gQ.png" /></figure><blockquote>同時可以驗證是否發布成功：<a href="https://cocoapods.org/pods/LittleSpock">https</a>：<a href="https://cocoapods.org/pods/LittleSpock">//cocoapods.org/pods/LittleSpock</a></blockquote><p>恭喜！現在，可以在您的專案使用 LittleSpock 來進行加/減運算，或是創造出自己的 pod 讓大家使用。</p><p>有任何問題歡迎底下留言，覺得 LittleSpock 好用，也可以給我多點掌聲！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2979099fbfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Search API]]></title>
            <link>https://medium.com/@spock.hsu/search-api-dd83e67c9431?source=rss-e55ade4a40a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd83e67c9431</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Spock 薛]]></dc:creator>
            <pubDate>Fri, 18 Jan 2019 15:33:59 GMT</pubDate>
            <atom:updated>2019-01-18T15:45:58.962Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*XqcAML3iZWRLnR_gczR28w.png" /></figure><p>最近剛好公司專案要使用這個在 iOS 9 就釋出的新 API，順便在這邊只裡一下收集到的資料，也可以直接往下滑尋找範例程式碼… (!有範例程式碼)</p><h4>簡介：</h4><p>iOS 9 SDK 中新的搜尋 API 包含下列 3 個主要元件：</p><p>1. [<a href="https://developer.apple.com/documentation/foundation/nsuseractivity#//apple_ref/occ/cl/NSUserActivity">NSUserActivity</a>]<br>可以將其編入Spotlight數據庫。這允許在用戶執行應用程序時為您的應用程序中的特定活動編制索引，例如導航到特定屏幕或創建一段內容。索引這些活動允許用戶通過iOS搜索用戶界面返回它們。<br> <br>2. [<a href="https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/WebContent.html#//apple_ref/doc/uid/TP40016308-CH8-SW1">Web Markup</a>]<br>允許來自網頁的結構化數據由Apple編制索引並顯示在iOS搜索UI中，以提供比標準Web搜索可能找到的更豐富的搜索結果。</p><p>3. [<a href="https://developer.apple.com/documentation/corespotlight">Core Spotlight</a>]<br> 是一個新框架，允許將應用中創建的內容添加到設備上的Spotlight索引。當用戶從應用程式添加到索引中的某個項目中選擇搜索結果時，應用程式會收到包含索引信息的深層鏈接，允許直接導航到用戶選擇的內容。</p><p>這些技術涉及 Spotlight 索引中提供的兩個隱私級別 — 公共和私有。所有Web Markup 都添加到 Apple 託管的公共 Spotlight 索引中，而 Core Spotlight 僅允許將應用程序內容編入私有設備上的聚光燈索引。只有索引的NSUserActivities 可以是公共的和私有的。</p><h4><strong>對於Spotlight的索引數據</strong></h4><p>1. 為了將一段應用程式內容添加到設備上的 Spotlight 索引，我們必須創建一個 CSSearchableItemAttributeSet 實例。在這裡，我們存儲有關我們想要編入索引的內容的信息。</p><pre><br>let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeData as String)<br></pre><p>2. 一但我們儲存了我們希望索引的屬性，我們需要將它們分配給 CSSearchableItem，CSSearchableItem 是傳遞給 Spotlight 進行索引的對象。</p><pre><br>let searchableItem = CSSearchableItem(uniqueIdentifier: stock.name, domainIdentifier: nil, attributeSet: attributeSet)</pre><p><strong>特別注意的是，我們傳入之前創建的屬性以及唯一的 uniqueIdentifier。選擇搜索結果時將使用此 uniqueIdentifier ，以便應用程式可以導航到所選的股票。</strong></p><p>3. 接著，我們通過使用 CSSearchableIndex.defaultSearchableIndex（）獲取對 Spotlight 索引的引用，並調用 indexSearchableItems:completionHandler:</p><pre><br> let searchableIndex = CSSearchableIndex.default()<br> searchableIndex.indexSearchableItems(searchableItems) { … }<br></pre><h4><strong>響應選擇搜索結果</strong></h4><p>當使用者點擊搜索結果後，要能跳轉到該應用程式的相應頁面時，首先在 appDelegate 上實現一個方法：</p><pre> <br>func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: <a href="http://twitter.com/escaping">@escaping</a> ([UIUserActivityRestoring]?) -&gt; Void) -&gt; Bool{ … }<br></pre><h4>補充</h4><p>1. CSSearchableItemAttributeSet<br>除了 example project 用到的那些屬性之外，其實還有很多可以使用：<br>所有這些屬性都列在 [<a href="https://developer.apple.com/documentation/corespotlight/cssearchableitemattributeset">CSSearchableItemAttributeSet</a>]說明文件中。</p><p>2. 畫面屬性</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*K3Ibbt_XcAlmnin7ApU3aw.png" /></figure><p>1. 指定與內容相關的縮略圖圖像。避免應用圖標圖像。（如果未指定，將自動顯示應用程序的圖標圖像。）如果圖像為方形，請準備180 x 180像素。橫向圖像被調整為水平180像素，垂直長圖像垂直調整為270像素。有關詳細信息 [<a href="https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/SearchUserExperience.html#//apple_ref/doc/uid/TP40016308-CH11-SW1">請參閱此</a>。]<br> <br>2. 標題長等於設備的寬度，過長將會被截斷。最好限制在90個字符以內。</p><p>3. 內容描述也會被截斷。最好限制在300個字符以內。（標題最多可顯示1行，說明可以是2行）</p><p>4. 可以指定緯度/經度並啟用supportsNavigation時，將顯示箭頭圖標。點按以啟動地圖應用程序。</p><p>5. 可以設置電話號碼並激活supportsPhoneCall後，將顯示電話圖標。點按即可撥打電話。（您只能顯示地圖和手機之一）</p><p>6. 搜尋結果的位置和順序是系統自動排定的，點擊頻率越高就越靠前面</p><p>7. 同一個應用程式，搜索結果列表默認顯示3個，然後展開最多 13個</p><p>8. 不確定searchItem 增加數量有否限制或引響效能</p><p><a href="https://developer.apple.com/documentation/corespotlight">https://developer.apple.com/documentation/corespotlight</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd83e67c9431" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>