<?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 Terry Huang on Medium]]></title>
        <description><![CDATA[Stories by Terry Huang on Medium]]></description>
        <link>https://medium.com/@terryhuanghd?source=rss-40138968af8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pYcJPinKzhP0OBGSHwP3Cg.png</url>
            <title>Stories by Terry Huang on Medium</title>
            <link>https://medium.com/@terryhuanghd?source=rss-40138968af8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:21:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@terryhuanghd/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[Swift 中 Array 存放 Weak Reference 的兩個方法 - Relearning Note]]></title>
            <link>https://medium.com/terry-engineer/swift-array-weak-reference-b647501ea6b2?source=rss-40138968af8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b647501ea6b2</guid>
            <category><![CDATA[nshashtable]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[weakreference]]></category>
            <dc:creator><![CDATA[Terry Huang]]></dc:creator>
            <pubDate>Sat, 10 Apr 2021 14:30:35 GMT</pubDate>
            <atom:updated>2021-04-10T14:30:35.540Z</atom:updated>
            <content:encoded><![CDATA[<h3>使用額外的 Wrapper</h3><p>以一個通用的 Weapper 來包裝目標，再以普通的 Array 來儲存。</p><pre><strong>class</strong> Weak&lt;T: AnyObject&gt; {<br>  <strong>weak</strong> <strong>var</strong> value: T?<br>  <strong>init</strong> (value: T) {<br>    <strong>self</strong>.value = value<br>  }<br>}</pre><pre>// Example<br><strong>var</strong> delegates = [Weak&lt;UITextViewDelegate&gt;]()</pre><pre>// Add<br>weakDelgates.append(Weak(value: delegate))</pre><pre>// Iterator<br>for dele in delegates {<br>  dele.value?.textViewDidChange?(textView)<br>}</pre><h3>使用 NSHashTable.weakObjects</h3><p>以通用的 NSHashTable 存放目標。</p><pre>// Example<br>var delegates = NSHashTable&lt;UITextViewDelegate&gt;.weakObjects();</pre><pre>// Add<br>delegates.add(delegate)</pre><pre>// Iterator<br>for dele in delegates.allObjects {<br>  dele.textViewDidChange?(textView)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*FF790Tf6wVg7CX2rDz5Y3g.png" /></figure><p>使用範例可以參考 Swift MulticastDelegate</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e648ec74b2630723dad8ea9901c048e4/href">https://medium.com/media/e648ec74b2630723dad8ea9901c048e4/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b647501ea6b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terry-engineer/swift-array-weak-reference-b647501ea6b2">Swift 中 Array 存放 Weak Reference 的兩個方法 - Relearning Note</a> was originally published in <a href="https://medium.com/terry-engineer">安郡尼爾筆記</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Common Swift Attributes - Relearning Note]]></title>
            <link>https://medium.com/terry-engineer/common-swift-attributes-1e25b30ddecc?source=rss-40138968af8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e25b30ddecc</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[attributes]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Terry Huang]]></dc:creator>
            <pubDate>Sat, 10 Apr 2021 07:37:35 GMT</pubDate>
            <atom:updated>2021-04-10T07:37:35.628Z</atom:updated>
            <content:encoded><![CDATA[<p>常見的 Swift Attributes 大致上分為兩類，一類是用來標註 Declaration，另一類是用來標註 Type。Attribute 會以 @ 開頭，之後是 Attribute Name，後面則有 optional 的 Attribute arguments</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*9F2w0eUvQRgDK1mZg97c5Q.png" /></figure><h3><strong>Declaration Attributes</strong></h3><h4>available</h4><p>用來標註 declaration 的生命週期。對應到相對的 Swift 版本、系統版本…等等。包含以下的 arguments</p><ul><li>unavailable: 用來標註「不支援」的 platform</li><li>introduced: 用來標註「開始支援」的最早版本</li><li>deprecated: 用來標註「不推薦使用」的最早版本</li><li>obsoleted: 用來標註「過時（失效）」的最早版本</li><li>message: 用來標註額外的說明訊息，當使用者使用了 deprecated or obsoleted 的 declarations</li><li>renamed: 用來標註「更名」的訊息</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*qJANiu7OmBhq9NSMGZ5U-w.png" /></figure><p>每個 arguments 將會以下列的平台或語言為起始，或以(*) 來代表所有平台</p><ul><li>iOS</li><li>iOSApplicationExtension</li><li>macOS</li><li>macOSApplicationExtension</li><li>macCatalyst</li><li>macCatalystApplicationExtension</li><li>watchOS</li><li>watchOSApplicationExtension</li><li>tvOS</li><li>tvOSApplicationExtension</li><li>swift</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*2AjoSHSoQ2ItbsDGop6E3Q.png" /></figure><h4>discardableResult</h4><p>這個標註能讓 compile 忽略那些「未處理回傳值」的函式呼叫警告。在設計多功能 Protocol 時相當好用。</p><h4>dynamicCallable</h4><p>能將 class, structure, enumeration, or protocol 的實例作為函式來呼叫，使用上需實作 dynamicallyCall(withArguments:) dynamicallyCall(withKeywordArguments:) 至少其中之一。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*WjDrR0RITZrbYWvi0O3wjA.png" /></figure><h4>main, NSApplicationMain, UIApplicationMain</h4><p>主要用來標註 top-level 的 entry point。在 Objective-C 專案中，保留了 main 函式作為啟動專案的入口。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*zhugVyXuLHgkuCfFXxuj1Q.png" /></figure><p>但在 swift 隱藏了這一個設計，並藉由 Attribute 來找到程序的入口。</p><ul><li>iOS: 透過 main, UIApplicationMain 對應到 UIApplicationDelegate</li><li>macOS: 透過 main, NSApplicationMain 對應到 NSApplicationDelegate</li></ul><p>當然，您也可以去除這個預設 attribute，並建立自己的 main 來實作接口。可參考官方說明，或是 <a href="https://github.com/mozilla-mobile/firefox-ios/blob/main/Client/Application/main.swift">Firefox iOS 的設計範例</a>。</p><h4>nonobjc, objc</h4><p>將 method, property, subscript, or initializer 標註為 objc 或 nonobjc。</p><p>常見使用情境為，需要用到 objc 的動態特性時，會需要將其標註為 objc。比如 selectors, method swizzling.</p><p>nonobjc 的 property 將無法 override 為 objc。反之則可以。</p><h4>propertyWrapper</h4><p>標註有 propertyWrapper 的 class, structure, or enumeration ，需實作 weappedValue，可將本身作為一個 property 的 attribute。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*s2rpFofNJ9ex4bjJ8uNgLw.png" /></figure><h3>Type Attributes</h3><h4>escaping</h4><p>當 closure 作為 argument 傳遞至 functions 時，其生命週期將會在 return 之後結束，但若該函式將其擷取並於之後做使用，則需要 escape（因為 function 和 closure 為 reference type）。</p><p><a href="https://docs.swift.org/swift-book/LanguageGuide/Closures.html#ID104">Closures - The Swift Programming Language (Swift 5.4)</a></p><h4>autoclosure</h4><p>在 closure 作為 argument 傳遞時，能夠自動針對 expression 建立一個 wrap</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*Djnu5BEFSUZ8uEOZSAhTrQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e25b30ddecc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terry-engineer/common-swift-attributes-1e25b30ddecc">Common Swift Attributes - Relearning Note</a> was originally published in <a href="https://medium.com/terry-engineer">安郡尼爾筆記</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift Array 之 filter, map, reduce 功能與 closure - Relearning Note]]></title>
            <link>https://terryhuanghd.medium.com/swift-array-%E4%B9%8B-filter-map-reduce-%E5%8A%9F%E8%83%BD%E8%88%87-closure-relearning-note-bca19f091f57?source=rss-40138968af8------2</link>
            <guid isPermaLink="false">https://medium.com/p/bca19f091f57</guid>
            <category><![CDATA[closure]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[filters]]></category>
            <dc:creator><![CDATA[Terry Huang]]></dc:creator>
            <pubDate>Wed, 09 Dec 2020 07:49:57 GMT</pubDate>
            <atom:updated>2020-12-11T02:21:37.720Z</atom:updated>
            <content:encoded><![CDATA[<p>在 Swift Array 中 filter, map, reduce 屬於比較進階的使用方法，雖然其功能都能透過其他的程式來完成，但透過這些方法更能夠把程式精煉成更直覺具有可讀性。</p><p>首先解析一下這些方法的位置</p><ul><li>Array Structure Conforms To</li><li>MutableCollection Protocol Inherits From</li><li>Collection Protocol Inherits From</li><li>Sequence Protocol</li></ul><h3>filter 方法</h3><p>filter 顧名思義就是一個篩選器，透過傳入的一個 isIncluded closure 來判斷某個 element 是要被包含或是剔除，輸出到結果的 Array</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w7iYdnl6UhWjnk0sry2igw.png" /></figure><h3>Closure 精煉之旅，以 filter 為例</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xV8s2AUWeG9Jqvquu7y6qw.png" /></figure><ol><li>在 Parameter 實作 Closure，省略定義無用的 Function 名稱</li><li>透過 Inferring Type From Context，省略可推敲的 Parameter Type 以及 Return Type</li><li>透過 Implicit Return From Single-Expression Closure，省略 return</li><li>透過 Shorthand Argument Names，省略 parameter name</li><li>透過 Trailing Closure，將 Closure 後置，省略大掛號</li></ol><h3>map 方法</h3><p>透過傳入的 transform closure 將原本的 Array 轉化成另一個 Array，每一個 Element 單獨處理。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mZErOfZTpn3ivn6ObgNsIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xcYuWPaqSKTauZBZlGSzfw.png" /></figure><h3>reduce 方法</h3><p>reduce 方法較為小複雜，可簡單的理解為丟進一個 closure，這個 closure 會依序的針對每個 element 執行，並把結果傳遞到下一個 element 的 closure result input；而初始值也就是第一個 element 處理 closure 時的 result input。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e-b8w755McBS9-7ajdB1dA.png" /></figure><p>也因為這樣依序處理並把結果傳遞的特性，常用來作類似統計的簡單邏輯。比如以下範例，只針對偶數 element 進行加總。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zyo8wt5JgsucVvrYXNT5Mw.png" /></figure><h3>One More Thing</h3><p>精簡程式寫法的另一個特殊用法是 Operator Method，當 Closure 僅透過一個 Operator 針對 Parameter 做處理便立即 Return 的這種情況，可再次縮減至一個 Operator（但無法做 Trailing Closure 須保留 Parameter 方式）。當然，這只用在特別簡單的單一邏輯關係。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PsKMf1x9aK_7aMZWst1ikg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bca19f091f57" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GCD(Grand Central Dispatch) 多執行緒 - Relearning Note]]></title>
            <link>https://medium.com/terry-engineer/gcd-grand-central-dispatch-%E5%A4%9A%E5%9F%B7%E8%A1%8C%E7%B7%92-relearning-note-ccbee0032d7f?source=rss-40138968af8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccbee0032d7f</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[dispatch-system]]></category>
            <category><![CDATA[gcd]]></category>
            <category><![CDATA[mobile-appde]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Terry Huang]]></dc:creator>
            <pubDate>Wed, 09 Dec 2020 00:10:43 GMT</pubDate>
            <atom:updated>2020-12-09T00:10:43.691Z</atom:updated>
            <content:encoded><![CDATA[<h3>GCD 機制</h3><p>GCD(Grand Central Dispatch) 是由 Apple 開發的一個函式庫，讓開發者能夠針對多核心裝置、多線程程序來最佳化，其設計是定義出「工作」以及「線程池」的概念。實際使用上，透過 Queue 的機制來方式工作，並依照 Queue 的特性，以及指派工作的類型來完成多執行緒的任務，提供非常簡單理解的使用方式。</p><h3>Queue 的類型</h3><h4>Serial 序列型</h4><p>序列型的 Queue，其中的任務會依序進行，一個接一個</p><h4>Concurrent 併發型</h4><p>併發型的 Queue，其中的任務會同時運行</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XK8kpFg4_avARHFd.jpg" /><figcaption>Source: Swift Dev Center</figcaption></figure><h3>Submission 的類型</h3><h4>Sync (Synchronous) 同步型</h4><p>以 Sync 派遣的任務，會在原執行緒等待其任務完成並返回</p><h4>Async (Asynchronous) 非同步型</h4><p>以 Async 派遣的任務，會開新執行緒進行任務，原執行緒並不會等待返回</p><h3>Queue 要怎樣產生？</h3><h4>內建的 main Queue</h4><p>main Queue 主要用以變更 UI 相關程序，特性為為 Serial Queue</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVyapb0ZMQWy-DhC759e6g.png" /></figure><h4>內建的 global Queue</h4><p>global Queue 特性為 Concurrent Queue，並依據 QoS 可分為 6個 Queue，其權重由高至低為</p><ul><li>userInteractive</li><li>userInitiated</li><li>`default`</li><li>utility</li><li>background</li><li>unspecified</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O0jkICcU36kPMcm7OCXdaQ.png" /></figure><h4>自建立的 Queue</h4><p>自建立的 Queue，可指定其特性為 Serial（預設）或是 Concurrent</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cw0sCdB6L-OGkGR5GFRUHQ.png" /></figure><h3>簡單範例: Concurrent Queue with Multiple Async Tasks</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WQYRuJaqhxoALiah4Cvmhw.png" /></figure><h3>Dispatch Group 監控多個 Work Item</h3><p>Dispatch Group 可監控跨越多個 Queue 的 Work Item，在完成所有的項目時，在特定的 Queue 中進行接下來的邏輯程式。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UK0-OC466e4nt8vMFVscXw.png" /></figure><h3>併發型 DispatchQueue 中唯我獨尊的 Atomic 任務</h3><p>在同一個併發的 DispatchQueue 的任務，會同時進行運作，但在可以透過特定的任務設定，讓此任務保有 Atomic 特性，完全與其他任務分開處理。那就是設定 Barier</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f-VgaruzyYtbCEDwKgVbUQ.png" /></figure><p>如範例中，Barier B等待了 A &amp; C 任務完全執行之後才開始運作，並等到運作玩之後 After 才接續進行。但很明顯的，Barier 的特性會造成效能的降低，所以在使用上也需要考量其必要性。</p><h3>Deadlock</h3><p>GCD 系統下，最常發生死結的狀況為：在序列 Dispatch Queue 的任務中，再 Sync 一個任務到 Dispatch Queue。因新指派的任務須等到原任務完成後才能進行，而原任務也在原地等待新任務完成，因此而形成死結。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KXzUpUzZLJpJYY-PuFgCUg.png" /></figure><h3>應用: Thread-Safe Array</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cefc1f1872b251bebcf42ff35789770e/href">https://medium.com/media/cefc1f1872b251bebcf42ff35789770e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccbee0032d7f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terry-engineer/gcd-grand-central-dispatch-%E5%A4%9A%E5%9F%B7%E8%A1%8C%E7%B7%92-relearning-note-ccbee0032d7f">GCD(Grand Central Dispatch) 多執行緒 - Relearning Note</a> was originally published in <a href="https://medium.com/terry-engineer">安郡尼爾筆記</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift String 為什麼故意把 Index 設計的這麼難用 -  Relearning Note]]></title>
            <link>https://medium.com/terry-engineer/swift-string-%E7%82%BA%E4%BB%80%E9%BA%BC%E6%95%85%E6%84%8F%E6%8A%8A-index-%E8%A8%AD%E8%A8%88%E7%9A%84%E9%80%99%E9%BA%BC%E9%9B%A3%E7%94%A8-relearning-note-3d8a504c155?source=rss-40138968af8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d8a504c155</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[string]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[index]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Terry Huang]]></dc:creator>
            <pubDate>Fri, 27 Nov 2020 07:03:43 GMT</pubDate>
            <atom:updated>2020-11-27T07:03:43.064Z</atom:updated>
            <content:encoded><![CDATA[<h3>Swift String 為什麼故意把 Index 設計的這麼難用 - Relearning Note</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ypwBr2HcsEeMmRDF16raNw.png" /></figure><blockquote>「你解釋解釋，為什麼字串無法直接以數字 index 取值、做 Subscript」</blockquote><h3>Unicode 歷史了解一下</h3><blockquote>Unicode，中文又稱萬國碼、國際碼、統一碼、單一碼，是電腦科學領域裡的一項業界標準。它對世界上大部分的文字系統進行了整理、編碼，使得電腦可以用更為簡單的方式來呈現和處理文字。</blockquote><p>早期電腦以一個 8 位元來代表一個文字狀態，以其中 7 個位元值 0~127 來代表空格、英文大小寫、數字、符號等等，也就是 ASCII 編碼（American Standard Code for Information Interchange)。</p><p>但電腦傳至多個國家之後，各國便將其文字編入其中，但 128~255 的空間位置也有限，因此也衍伸出了多位元組的編碼方式。比如台灣早前電腦的中文系統，如：倚天中文，大五碼…；而簡體中文也發展出 GB2312、GBK…等等。</p><p>為了解決各國編碼不同而造成的問題，國際化標準組織 (ISO) 決定解決這個問題，建立 ISO/IEC 推出了通用字元集 UCS (Universal Character Set / Universal Multiple-Octet Coded Character Set)。同時期也有軟體商 Xerox、Apple…等等嘗試建造單一字元集統一碼 (Unicode)。</p><p>後來雙方達成一致，合併其開發成果。同意保持兩者標準的碼表相容，並緊密地共同調整任何未來的擴充。</p><h3>傳統的 String 設計</h3><p>以 C++ 語言為例，最傳統的 std::string 以 char 組成，一個 char 一個 byte；在 Java 中一個 char 則為 2 byte。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hhhjqOmBBWPJqN7kGKiJpQ.png" /></figure><p>這樣設計的好處是，每隔字元使用的記憶體是固定的，因此也可以透過簡單的加減來計算出特定字元的記憶體位置。但缺點就非常明顯了，當字串用來處理多位元字符時，便會發生 char 長度與可視的長度不同。</p><h3>Swift 與 Unicode Sclar</h3><p>以現有的 Unicode 規劃來說，涵蓋 U+0000 到 U+10FFFF，共有1,112,064個碼位（code point），以常見的 UInt32 (4 byte)來紀錄，便能代表一個任意數值的碼位。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*bsNnQsPkJVc-0TQ-4gGh4w.png" /></figure><p>而在 Swift 中也確實有 Unicode Scalar 型別能紀錄任意的單一 Unicode Code Point。所以，如果以此為單位來規劃「字串」與「字元」系統，不就能設計出完美的解決方案了嗎？但 Swift 中 String 卻還不是由 Scalar 組成，到底是為什麼？</p><blockquote><strong>“因為應該視為一個 Unit 處理的單元，可能由多個 Unicode Code Point 組成！沒錯，因為有個東西叫做 Grapheme Cluster”</strong></blockquote><h3>Grapheme Cluster 駕到</h3><p>早在 Unicode 3.2 中，便引入了 Grapheme Cluster，能將數個 Unicode Code Point 組成一個 Unit，這樣一個 Unit 在使用者情境下應視為一個單位「字」處理。以下為最常見的一些用法：</p><ul><li>組合韓文，比如：한，可由 3 個 Code Point 組成（ᄒ, ᅡ, ᆫ）</li><li>組合字元，比如：ò，是由 2 個 Code Point 組成（o, ̀）</li><li>修飾 Emoji，比如：🚴🏾，是由 2 個 Code Point 組成（ 🚴, 🏾）</li></ul><h3>Swift 的字與字串</h3><p>在追求極致的處理環境下，在 Swift 中定義了一個完美的「邏輯環境」：應該被當為單一 Unit 處理的「字」型別為 Character，一個 Character（字）由一個或多個 Unicode Scalar 組成，而字串 String 則由多個 Character 組成。</p><blockquote>The `Character` type represents a character made up of one or more Unicode scalar values, grouped by a Unicode boundary algorithm. Generally, a `Character` instance matches what the reader of a string will perceive as a single character. Strings are collections of `Character` instances, so the number of visible characters is generally the most natural way to count the length of a string.</blockquote><p>由以下的範例來看，「한Dòg🚴🏾」這在文字上可簡易辨識成 5 個 Unit，在 Swift String 中完全能夠正確的 Count 出 5 的長度，但其實是由 9 個 Scalar 組成，也能以 11 個 UTF-16 或是 22 個 UTF-8 表示。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6NBv1jAfQIjqsLuk7pYHHw.png" /></figure><p>題外話，就連 Swift 語言本身都是極端的 Unicode Friendly，您甚至可以用來命名變數。（相信大家已經見怪不怪）</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EsXnB98Kj7urGlzzh14C3Q.png" /></figure><h3>毀天滅地的複雜度</h3><p>也就因為了 String 中每個 Character（字）可能由多個 Unicode Scalar 組成，因此並無法簡單地從記憶體位置的差距，來計算出某個 Character（字）的位置。因此，當你需要第 5 個 Character（字）時，Swift 需要從 String 的 startIndex 往後逐字跳躍，直到完成後才能取得正確的資料。換句話說，以任意數字為 Index 取得 Character（字）的複雜度遠比想像中的高。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*krIgy8EWqFrcN0PrnmuEug.png" /></figure><p>因此，針對 Swift String 字串相關 Protocol 設計，在後期便直接把數字取字元的概念移除，以更多元化的 Index 進退與設計，來滿足字串處理的需求。</p><p>P.S. 其實在 Swift 2~3 的版本時，曾經是棄用 Index 支援 Int 的，但在 4 版之後又回歸了 Index 設計。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*bchEETnkNgi9kx7ihzareQ.png" /></figure><p>當然，網路上流通了非常多的 String Extension 語法糖，能夠讓使用者簡單的回到從前，但這一切剛好也就抹滅了這個故意設計的用意。也就只有在瞭解了這背後的設計原因，才更能知道如何讓程式進一步的優化。</p><p>P.S. 如果對於 String.Index 設計有興趣，也能參考<a href="https://github.com/apple/swift/blob/main/stdlib/public/core/StringIndex.swift">原始檔案</a>中的說明</p><h3>Reference</h3><ul><li><a href="https://zh.wikipedia.org/zh-tw/Unicode">https://zh.wikipedia.org/zh-tw/Unicode</a></li><li><a href="https://github.com/apple/swift/blob/main/stdlib/public/core/StringIndex.swift">String.Index Source Code</a></li><li><a href="https://github.com/apple/swift/blob/274c1097bbf01678a708cf7c8804a4089c7430ae/stdlib/public/core/UnavailableStringAPIs.swift.gyb#L13-L52">https://github.com/apple/swift/blob/274c1097bbf01678a708cf7c8804a4089c7430ae/stdlib/public/core/UnavailableStringAPIs.swift.gyb#L13-L52</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d8a504c155" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terry-engineer/swift-string-%E7%82%BA%E4%BB%80%E9%BA%BC%E6%95%85%E6%84%8F%E6%8A%8A-index-%E8%A8%AD%E8%A8%88%E7%9A%84%E9%80%99%E9%BA%BC%E9%9B%A3%E7%94%A8-relearning-note-3d8a504c155">Swift String 為什麼故意把 Index 設計的這麼難用 -  Relearning Note</a> was originally published in <a href="https://medium.com/terry-engineer">安郡尼爾筆記</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift Protocol Q&A - Relearning Note]]></title>
            <link>https://medium.com/terry-engineer/swift-protocol-q-a-4dc993f34838?source=rss-40138968af8------2</link>
            <guid isPermaLink="false">https://medium.com/p/4dc993f34838</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[protocol]]></category>
            <category><![CDATA[protocol-oriented]]></category>
            <dc:creator><![CDATA[Terry Huang]]></dc:creator>
            <pubDate>Tue, 24 Nov 2020 17:31:03 GMT</pubDate>
            <atom:updated>2020-11-24T17:31:34.269Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0uGueaNPQ5VYpmRxE15z_g.png" /></figure><h3>Q: 什麼是 Protocol</h3><p>Protocol 用來定義一個特定<strong>「任務」</strong>或<strong>「功能」</strong>的藍圖，包含其<strong>「方法」</strong>、<strong>「屬性」</strong>以及<strong>「其他的要求」</strong>。Protocol 能被 <strong>Class, Struct, Enumeration</strong> 採用並實踐。</p><blockquote>A protocol defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. The protocol can then be adopted by a class, structure, or enumeration to provide an actual implementation of those requirements. Any type that satisfies the requirements of a protocol is said to conform to that protocol.<br>– The Swift Programming Language Guide by Apple</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gX_f35blzY7XnJ-rrfnN7A.png" /></figure><h3>Q: Protocol 能定義哪些需求</h3><ul><li>屬性需求 Property Requirements</li><li>方法需求 Method Requirements</li><li>初始化需求 Initializer Requirements</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G0v4QZL102IT8EUeU-Vpag.png" /><figcaption>Protocol with “Property”, “Method” and “Initializer” requirements</figcaption></figure><h3>Q: Swift Protocol vs Java Interface</h3><h4>類似功能</h4><ul><li>能夠用於抽象化（Abstraction）以及委派（Delegation）等設計模式（Design Pattern）</li><li>可作為型別用於變量（Protocols as Types）與集合（ Collections of Protocol Types）。也能實例確認（Checking for Protocol Conformance）</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PQKGLMJM8lOBXPqYSbPvaQ.png" /><figcaption>“WithName” Protocol as Types in Employee</figcaption></figure><h3>Swift Protocol 功能</h3><ul><li>Protocol 除了方法需求外，能定義屬性、初始化需求</li><li>Protocol 能以 Extension 在既有的存取範圍中，延伸新增屬性、方法，並能實作其邏輯行為</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xz4V-FN_KJTeF1FgHWXocA.png" /><figcaption>Protocol Extension with function implementation</figcaption></figure><ul><li>Protocol 能「繼承」Protocol（如圖中 Resident）</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lboeq_lqfOZoLuj6TOAgsw.png" /><figcaption>Protocol Inheritance</figcaption></figure><ul><li>Protocol 支援 Composition（如圖中 sayHello）</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R9VT3D2vqKKhK2RpgrwKMw.png" /><figcaption>Parameter with Protocol Composition</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4dc993f34838" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terry-engineer/swift-protocol-q-a-4dc993f34838">Swift Protocol Q&amp;A - Relearning Note</a> was originally published in <a href="https://medium.com/terry-engineer">安郡尼爾筆記</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[開始使用 Android App Bundle]]></title>
            <link>https://medium.com/terry-engineer/android-app-bundle-f7792784f2c8?source=rss-40138968af8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7792784f2c8</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[app-bundle]]></category>
            <category><![CDATA[google]]></category>
            <dc:creator><![CDATA[Terry Huang]]></dc:creator>
            <pubDate>Fri, 05 Oct 2018 09:41:19 GMT</pubDate>
            <atom:updated>2018-10-05T09:41:19.714Z</atom:updated>
            <content:encoded><![CDATA[<p>隨著 Android Studio 3.2 在 Stable Channel 釋出後，全新的 App Bundle 功能也完整的呈現在所有開發者面前，這一個嶄新的技術能帶來怎樣的好處，或是給出了怎樣的 Android App 未來的架構，讓我們嘗試解析一下</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F9D63S4ZRBls%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D9D63S4ZRBls&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F9D63S4ZRBls%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b595248d18d1366444a545c1427c533/href">https://medium.com/media/1b595248d18d1366444a545c1427c533/href</a></iframe><h3>What &amp; Why App Bundle</h3><p>這個答案很簡單，整個 App Bundle 的精神，就是圍繞著一個字來發展的，就是：<strong>『小』</strong>，如何讓使用者從 Play Store 下載最小的資料，便能開始使用 App 的功能。這個方向與去年所推出的 Instant Apps 不謀而合，App Bundle 模組化的設計方式，也是來自於此。在實作 App Bundle 上，Google 目前提供了量個方法</p><ul><li>Dynamic Delivery: 只下載使用者機器需要的資源</li><li>Dynamic Feature: 只下載最核心的功能，其他的用到再下載</li></ul><h3>Dynamic Delivery</h3><h4>只給使用者需要的資源</h4><p>當使用者交付給 Google Play App Bundle 封裝檔案（*.aab）之後，當使用者下載 App 時，便會依據使用者目前的機器組態，給予最佳化容量的 APK，簡單來說，Google Play 會幫你做出「只包含目前機器」所需要的資源的 APK</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*nndOu0ShnpNSbuOMW02ZKQ.png" /></figure><h4>完全免動刀</h4><p>分開封裝的資源有三大類，分別是是<strong>「語言」、「處理器架構」、「屏幕密度」</strong>。其中最讓人振奮的是，這一切，完全都不用程式碼的變動，就可以達成！當然，您還是得改成使用 App Bundle 封裝</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*zY9QRy_m_SNS-K9fu4JUjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qlCnxzYXn6AwUJTi-0BNuA.png" /><figcaption>Google Play 會將 App Bundle 自動做成 Base 以及各 Configuration APK</figcaption></figure><h3>Dynamic Feature</h3><p>注意：Dynamic Feature 功能目前尚在測試階段</p><h4>運作原理</h4><p>概念與 Instant App 類似，將 App 切分成 Base 與數個 Dynamic Feature，在需要的時候，透過 Play Core Library 來進行下載</p><h4>Dynamic Feature 也可 Dynamic Delivery</h4><p>在整個 App Bundle 的運作中，除了 Base 程式能夠自動化將資源進行 Dynamic Delivery 之外，Dynamic Feature 的 APK 也能夠自動化進行 Dynamic Delivery</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j2GYIYK-Ljt0byuCFL3e-w.png" /></figure><h4>實作方法</h4><ul><li>詳細實做說明可參考：<a href="https://developer.android.com/guide/app-bundle/playcore">Download modules with the Play Core Library</a></li></ul><h3>注意事項</h3><h4>僅支援 Android 5.0 (API level 21)</h4><p>僅支援 API level 21 以上的機器（<a href="https://developer.android.com/about/dashboards/">根據公開資訊</a>目前占比已達 88%），在更低的版本，還是會下載到完整大小的 APK</p><h4>需啟用 Google Play App Signing</h4><p>既然透過 Google Play 來完成 APK 的封裝，也就代表需要支援 Google Play App Signing，您必須將封裝的 Key 提交給 Google 來支援這個功能</p><ul><li><a href="https://support.google.com/googleplay/android-developer/answer/7384423?hl=zh-Hant">參考資料</a></li></ul><h4>非強制，也不是一定適用</h4><p>雖然 Google Play 新增了 App Bundle 支援可以說是好處多多，但目前並不是強制使用；依照筆者的猜測，也不可能強制實施，畢竟對於特定的 App 來說，效用並不大，比如：使用第三方函式庫的遊戲</p><h4>目前僅 Google Play 支援</h4><p>雖然 App Bundle 已經是 Open Source 專案，但是要等待更多的發布渠道能夠支援，應該還是需要很長的時間。分析原因很簡單，就算不計算發佈平台所需耗費的資源，光是還要讓開發者願意授權給平台進行 app signing，信任度也是一個很大的考驗</p><h4>大小限制依然存在</h4><p>使用者機器下載的到 APK（base + configuration）仍不能超過 100 M</p><h4>不支援 APK expansion（長嘆一聲）</h4><h3>筆者想法：聊勝於無</h3><p>以現在硬體與網路的發展，100m 限制沒放寬，甚至不支援 APK extension，這樣的 App Bundle 能優化的幅度可以說是相當有限，雖然在成本不高的情形下，順手 Dynamic Delivery 一下還算是方便；但是對於真正需要的高容量外部資源類型 App，甚至是針對多渠道的支援，還是丟回給平台、開發者自己去解決，最後的結果，可想而知，開發商還是會傾向施作「通用架構」。這從遊戲現況就可預見，搭配 APK Expansion 推出 Google Play <a href="https://developer.android.com/google/play/licensing/">Application Licensing</a> 下載架構，可以說是乏人問津，Dynamic Feature 可能也會步上這樣的後塵</p><h3>附錄: APK format vs App Bundle format</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*aQCKqAF83SnDT0flssYrkA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PkLz54EaguQBhYOWT_hTsA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7792784f2c8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terry-engineer/android-app-bundle-f7792784f2c8">開始使用 Android App Bundle</a> was originally published in <a href="https://medium.com/terry-engineer">安郡尼爾筆記</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[手動整合 SDKBOX on Cocos2d-x 3.x — Android]]></title>
            <link>https://medium.com/terry-engineer/sdkbox-on-cocos2d-x-3-x-android-8c39e960e655?source=rss-40138968af8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c39e960e655</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[cocos2dx]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[sdkbox]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Terry Huang]]></dc:creator>
            <pubDate>Wed, 03 Oct 2018 10:20:01 GMT</pubDate>
            <atom:updated>2019-01-26T04:42:19.675Z</atom:updated>
            <content:encoded><![CDATA[<h3>手動整合 SDKBOX on Cocos2d-x 3.x — Android</h3><p>前情提要可參考：<a href="https://medium.com/terry-engineer/sdkbox-iap-on-cocos2d-x-3-x-ios-e2c958cacc75">手動整合 SDKBOX on Cocos2d-x 3.x — iOS</a></p><h3>沒成功過的原廠 Patch</h3><p>由於 Cocos2d-x 建立專案的方式相當多元，而且各版本的變異性很大，造就了自動化得整合非常困難，小弟我幾乎沒有印象有使用成功過。除此之外，由於 Open Source 與架構上的設計，非常方便讓使用者針對基底程式進行修改，也相當性的增加了難度。所以，還是筆記一下手動整合的細部步驟吧！</p><h3>手動整合 SDKBOX on Android Project</h3><h4>a. 下載 Bundle File for cocos2d-x v3.x</h4><p>請到<a href="http://www.sdkbox.com/integrations/iap#versions">這個網頁</a>來下載，在 #3 install manually 中，選擇下載 Bundle file（或是<a href="http://download.sdkbox.com/installer/v1/sdkbox-iap_v2.4.1.1.tar.gz">直接點我下載</a>）</p><h4>b. 將所需的 Library 引入</h4><ol><li>將下載的 Bundle file/plugin/android/libs 中的 PluginIAP.jar 以及 sdkbox.jar 複製到專案使用的 cocos2d library 中（billing 等等透過 gradle 引入最新版本）</li></ol><pre><strong># 使用 cocos2d-x source 版本</strong><br>cocos2d/cocos/platform/android/java/libs<br>cocos2d/cocos/platform/android/libcocos2dx/libs</pre><pre><strong># 使用 cocos2d-x prebuilt 版本</strong><br>&lt;project_root&gt;/libs</pre><p>2. 在 App 的 build.gradle 引入 billing library</p><pre>implementation <strong>&#39;com.android.billingclient:billing:1.1&#39;</strong></pre><h4>c. 修改 AndroidManifest.xml</h4><ol><li>新增 uses-permission</li></ol><pre>&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;<br>&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;<br>&lt;uses-permission android:name=&quot;com.android.vending.BILLING&quot;/&gt;</pre><p>2. 在 Application 中新增 Activity</p><pre>&lt;activity<br>android:name=&quot;com.android.billingclient.api.ProxyBillingActivity&quot;<br>android:configChanges=&quot;keyboard|keyboardHidden|screenLayout|screenSize|orientation&quot;<br>android:theme=&quot;@android:style/Theme.Translucent.NoTitleBar&quot;/&gt;</pre><h4>d. 複製 JNI</h4><ol><li>將下載的 Bundle file/plugin/android/jni 中的 PluginIAP 以及 sdkbox 兩個資料夾，複製到專案使用的 cocos2d library 中</li></ol><pre>proj.android-studio/app/jni</pre><h4>e. 修改專案中 Android.mk</h4><ol><li>新增 LOCAL_WHOLE_STATIC_LIBRARIES</li></ol><pre><strong># 如果原本‘已有’ LOCAL_WHOLE_STATIC_LIBRARIES，那就再繼續加上</strong><br>LOCAL_WHOLE_STATIC_LIBRARIES += PluginIAP LOCAL_WHOLE_STATIC_LIBRARIES += sdkbox</pre><pre><strong># 如果原本‘無’ LOCAL_WHOLE_STATIC_LIBRARIES，那就直接加入</strong><br>LOCAL_WHOLE_STATIC_LIBRARIES := PluginIAP sdkbox</pre><p>2.加入以下 import 設定</p><pre><strong># 須在所有 import-module 之前</strong><br>$(call import-add-path,$(LOCAL_PATH))</pre><pre><strong># 新增 import-module</strong><br>$(call import-module, ./sdkbox)<br>$(call import-module, ./pluginiap)</pre><h4>f. 修改專案中 Application.mk (僅 Cocos2d-x v3.0 — v3.2 需要)</h4><p>將 APP_STL := c++_static<strong> 改為 </strong>APP_STL := gnustl_static</p><h4>g. 修改 Cocos2dxActivity.java</h4><pre><strong># 檔案位於以下路徑</strong><br>cocos2d/cocos/platform/android/java/src/org/cocos2dx/lib/</pre><ol><li>新增 import</li></ol><pre><strong>import</strong> com.sdkbox.plugin.SDKBox;</pre><p>2. 在 onCreate 中，新增 SDKBox 初始化程序</p><pre><strong># 在 onLoadNativeLibraries 之後新增 SDKBox.init</strong><br>onLoadNativeLibraries();<br>SDKBox.init(<strong>this</strong>);</pre><p>3. 在 Activity Lifecycle 事件、Back按鈕事件、Activity 返回事件中新增程序</p><pre><strong># onStart, onStop, onResume, onPause<br># onBackPressed, onActivityResult</strong></pre><pre><a href="http://twitter.com/Override">@Override</a><br>protected void onStart() {<br>      super.onStart();<br><strong>      SDKBox.onStart();</strong><br>}</pre><pre><a href="http://twitter.com/Override">@Override</a><br>protected void onStop() {<br>      super.onStop();<br><strong>      SDKBox.onStop();</strong><br>}</pre><pre><a href="http://twitter.com/Override">@Override</a><br>protected void onResume() {<br>      super.onResume();<br><strong>      SDKBox.onResume();</strong><br>}</pre><pre><a href="http://twitter.com/Override">@Override</a><br>protected void onPause() {<br>      super.onPause();<br><strong>      SDKBox.onPause();</strong><br>}</pre><pre><a href="http://twitter.com/Override">@Override</a><br>public void onBackPressed() {<br><strong>      if(!SDKBox.onBackPressed()) {<br></strong>        super.onBackPressed();<strong><br>      }</strong><br>}</pre><pre><a href="http://twitter.com/Override">@Override</a><br>protected void onActivityResult(int requestCode, int resultCode, Intent data) {<br><strong>      if(!SDKBox.onActivityResult(requestCode, resultCode, data)) {<br></strong>        super.onActivityResult(requestCode, resultCode, data);<strong><br>      }</strong><br>}</pre><h4>h. 更改 AppActivity 繼承</h4><p>編輯負責專案啟動的 AppActivity.java（應該在 org.cocos2dx.cpp 的 namespace 底下），更改其繼承自 SDKBoxActivity</p><pre><strong>public class </strong>AppActivity <strong>extends </strong>com.sdkbox.plugin.SDKBoxActivity {</pre><h3>錯誤排除</h3><h4>a. 使用與 bundle 同版本的 support library</h4><h4>b. 啟用 multiDex，<a href="https://developer.android.com/studio/build/multidex">點我看說明</a></h4><h3>新增設定檔案</h3><ul><li>新增 sdkbox_config.json 檔案，放置在專案資源資料夾 Resources 底下</li><li>可依照平台、Plugin、加入設定資料，比如範例中，將 android 的 iap 中，加入了一個 item，這個 item 需要與 <a href="https://play.google.com/apps/publish/">Google Play Console</a> 中的物品 ID 設定相符合，key 也需要與 <a href="https://play.google.com/apps/publish/">Google Play Console</a> 中授權公開金鑰相同</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*X3KqNzJP8B-mAeXp90Zbog.png" /><figcaption>範例中 unlockstories 即為 Item Id，可依照需求列入多項商品</figcaption></figure><h3>其他</h3><ul><li>初始化函式庫請參考：<a href="https://medium.com/terry-engineer/sdkbox-iap-on-cocos2d-x-3-x-ios-e2c958cacc75">手動整合 SDKBOX on Cocos2d-x 3.x — iOS</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c39e960e655" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terry-engineer/sdkbox-on-cocos2d-x-3-x-android-8c39e960e655">手動整合 SDKBOX on Cocos2d-x 3.x — Android</a> was originally published in <a href="https://medium.com/terry-engineer">安郡尼爾筆記</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[手動整合 SDKBOX on Cocos2d-x 3.x — iOS]]></title>
            <link>https://medium.com/terry-engineer/sdkbox-iap-on-cocos2d-x-3-x-ios-e2c958cacc75?source=rss-40138968af8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2c958cacc75</guid>
            <category><![CDATA[sdkbox]]></category>
            <category><![CDATA[cocos2dx]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Terry Huang]]></dc:creator>
            <pubDate>Mon, 01 Oct 2018 09:48:04 GMT</pubDate>
            <atom:updated>2018-10-03T04:06:06.432Z</atom:updated>
            <content:encoded><![CDATA[<p>SDKBOX 是一個強大的免費第三方集成工具，支援了各大遊戲開發平台，比如: Cocos2d-x, Unity, Unreal Engine…等等。提供了幾乎遊戲開發會用到的功能集成，像是 IAP 服務（支援雙平台）、Google Play Service 服務、廣告服務（各大平台皆有支援：如 AdMob, Unity Ads…等等）、統計服務（Google Analytics, Flurry, Firebase…等等）、還有雲端設定、遊戲計分平台（Play Game 以及 Game Center）、Push Nitification…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*Rwr2-cLIt6cOEubJYytYDA.png" /><figcaption>SDKBOX 基礎服務</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*hq3CBQpyKlBYP5GAyvsnRg.png" /><figcaption>SDKBOX 整合的第三方廣告平台</figcaption></figure><h3>經常性失效的 Cocos2d-x 簡易整合工具</h3><p>由於 Cocos2d-x 將程式源碼整合再專案中，在每一次的 Cocos 程式改版後，通常會造成簡易整合工具完全失效的狀況，而且好像也沒有要修好的跡象，所以，還是筆記一下手動整合方法 XD</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*_yE_c2PtO-OS0mKp-hcbqg.png" /><figcaption>年久失修的 Project Management Tool</figcaption></figure><h3>手動整合 SDKBOX on iOS Project</h3><h4>a. 下載 Bundle File for cocos2d-x v3.x</h4><p>請到<a href="http://www.sdkbox.com/integrations/iap#versions">這個網頁</a>來下載，在 #3 install manually 中，選擇下載 Bundle file（或是<a href="http://download.sdkbox.com/installer/v1/sdkbox-iap_v2.4.1.1.tar.gz">直接點我下載</a>）</p><h4>b. 將函式庫加到專案</h4><p>將 Bundle 中 plugins/ios 裡面的 sdkbox.framework 以及 PluginIAP.framework 拉到專案中，勾選 Copy items if needed</p><h4>c. 加入其他函式庫</h4><p>在專案設定中，將 Linked Frameworks and Libraries 加入以下</p><pre>Security.framework<br>StoreKit.framework<br>AdSupport.framework<br>SystemConfiguration.framework</pre><h4>d. 更改編譯設定</h4><ul><li>取消 Bitcode 支援，可至專案設定的 Build Settings 中取消</li><li>取消 Transport Security，修改 info.plist 加入以下</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*6XTjj-aNblzHAMFyk6rM7w.png" /></figure><ul><li>將專案的 Capabilities 中的 In-App Purchase 設定為 Enable</li></ul><h3>新增設定檔案</h3><ul><li>新增 sdkbox_config.json 檔案，放置在專案資源資料夾 Resources 底下</li><li>可依照平台、Plugin、加入設定資料，比如範例中，將 iOS 的 iap 中，加入了一個 item，這個 item 需要與 <a href="https://appstoreconnect.apple.com/">App Store Connect</a> 中的物品 ID 設定相符合，範例中 unlockstories 即為 Item Id，可依照需求列入多項商品</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*hmxEQnyX5AfWFoy1ioPkug.png" /><figcaption>sdkbox_config.json 範例</figcaption></figure><h3>初始化函式庫</h3><p>您可以透過呼叫 Static 函式來完成初始化的動作，建議在 AppDelegate::applicationDidFinishLaunching() 或是AppController:didFinishLaunchingWithOptions() 作動</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*gNmBsoTsF8_gG7-98qd0ow.png" /></figure><h4>可設定監聽器來處理各種處理狀態</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*d502QmSv0EIROwxjW7lt7w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2c958cacc75" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terry-engineer/sdkbox-iap-on-cocos2d-x-3-x-ios-e2c958cacc75">手動整合 SDKBOX on Cocos2d-x 3.x — iOS</a> was originally published in <a href="https://medium.com/terry-engineer">安郡尼爾筆記</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[閱讀筆記：Etsy DevOps 特點]]></title>
            <link>https://medium.com/terry-engineer/etsy-devops-555cf7d058c4?source=rss-40138968af8------2</link>
            <guid isPermaLink="false">https://medium.com/p/555cf7d058c4</guid>
            <category><![CDATA[etsy]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Terry Huang]]></dc:creator>
            <pubDate>Fri, 13 Jul 2018 17:31:17 GMT</pubDate>
            <atom:updated>2018-07-13T17:31:17.883Z</atom:updated>
            <content:encoded><![CDATA[<p>彙整了 Esty DevOps 的特色，並不是使用工具的介紹喔！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DPqDJU5AON9YBMsufueEqA.jpeg" /></figure><h3>讓一切快速起跑</h3><p>開發者使用 VM 環境，讓權限設定、開發基礎資源、開發環境、編譯環境、快捷鍵、可能需要的一切支援資料，都能在短時間內設定到位，即使損毀了也可以輕易地重建。即使是第一天到職的新人，也能快速地上手</p><h3>讓開發者放手去做</h3><p>VM 環境，以及透過設計好的 Test Flow，讓開發者能夠完全放手安心的開發，不用擔心造成系統的損害</p><ol><li>Local Test：在 Local 環境涵蓋有最底層的 Unit Test 與 Function Test</li><li>Try Server Test：再提交至 Main Branch 之前，還有一個與 Production Continuous Integration 環境相同的 Jenkins Cluster 可測試</li><li>Code Review：完成了 Unit Test, Function Test, Try Server Test 之後，由交付者判斷，是否需要請求其他同事進行 Code Review</li><li>Production CI Test：根據使用場景可能有 Pull Request 或是 Push Queue 模式，將程式 Commit 到 Main Branch，然後便會透過 Deployinator 將程式部署到 QA Server 建置，進行 Production CI 測試</li><li>Go Production</li></ol><h3>產地就是銷售地</h3><p>除了快速交付之外，讓產品的開發與測試都能在相近的環境中運作，更能夠降低非必要的錯誤</p><ul><li>VM 中設定了與 Production 一樣的環境，讓開發者可以在早期階段就確定執行結果</li><li>Try Server 的測試環境與 QA Server 的測試環境相同</li></ul><h3>讀萬卷書不如行萬里路</h3><ul><li>設計簡單的「First Push」首推計畫，讓新人能夠確切地完成 Work Flow 中的每個步驟，比如：在網站的員工介紹中新增自己的資料</li></ul><h3>文化</h3><ul><li>信任：透過信任的文化，來達成更有效率的成果，比如：讓交付者自行判斷是否需要 Code Review，比起制式化的審查制，更能夠專注資源</li><li>進步 &gt; 咎責：在完備的 Work Flow 中，能夠盡可能地避免開發者犯下明顯、重複性的錯誤，當錯誤發生時，能夠吸取教訓並優化出更好的流程</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=555cf7d058c4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terry-engineer/etsy-devops-555cf7d058c4">閱讀筆記：Etsy DevOps 特點</a> was originally published in <a href="https://medium.com/terry-engineer">安郡尼爾筆記</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>