<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 李昇輯 on Medium]]></title>
        <description><![CDATA[Stories by 李昇輯 on Medium]]></description>
        <link>https://medium.com/@jimmylevelup?source=rss-15a224c4171d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*EPtOAlOoJUg45NZO</url>
            <title>Stories by 李昇輯 on Medium</title>
            <link>https://medium.com/@jimmylevelup?source=rss-15a224c4171d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 10:26:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jimmylevelup/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[製作可愛貓貓圖Widget]]></title>
            <link>https://medium.com/@jimmylevelup/%E8%A3%BD%E4%BD%9C%E5%8F%AF%E6%84%9B%E8%B2%93%E8%B2%93%E5%9C%96widget-0201e58c5762?source=rss-15a224c4171d------2</link>
            <guid isPermaLink="false">https://medium.com/p/0201e58c5762</guid>
            <category><![CDATA[cats]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[widget]]></category>
            <dc:creator><![CDATA[李昇輯]]></dc:creator>
            <pubDate>Fri, 26 Jul 2024 08:29:51 GMT</pubDate>
            <atom:updated>2024-07-26T08:29:51.664Z</atom:updated>
            <content:encoded><![CDATA[<p>最近買了新 iPad 想要好好利用大螢幕，想要放好多貓貓圖可惜目前有安裝的 app 只有 reddit 有一個貓貓日期 widget，但是他太小了，而且加入多個 widget 的話，每個都是一樣的圖片。種種困擾於是想自己做一個簡單的</p><p>搜尋一下馬上找到 thecatapi，每次打 api 會回傳一張隨機圖片，完全就是我想要的，還不用錢</p><p>高速做一個 prototype</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4wGL5ilAO37Ve-IvN69Y1g.png" /></figure><p>雖然已經是每個 widget 都送自己的 request，看起來 iOS 會對內容做最佳化，讓同樣大小的 widget 只有一個內容。為了要讓每個 widget 是真正的不同 instance，需要引入一個毫無意義的參數。</p><p>詳細的做法是加入 widget configuration，裡面有一個 string 參數。在主畫面加入 widget 之後，再編輯小工具輸入不同的參數就可以</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VzeIuixp16jwhmznHfL-0Q.png" /></figure><p>可以參考這裡的 code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8291092302e77f6d285090073f7f6a0f/href">https://medium.com/media/8291092302e77f6d285090073f7f6a0f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0201e58c5762" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Name Collision in Swift]]></title>
            <link>https://medium.com/@jimmylevelup/name-collision-in-swift-7cca25f169ac?source=rss-15a224c4171d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cca25f169ac</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[李昇輯]]></dc:creator>
            <pubDate>Tue, 16 Aug 2022 10:50:14 GMT</pubDate>
            <atom:updated>2022-08-16T10:50:14.656Z</atom:updated>
            <content:encoded><![CDATA[<p>最近在準備支援 Xcode14，發現有些 xcframework 沒有用 module stability，導致沒辦法 compile，大概是像這樣的錯誤訊息</p><p><em>Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler</em></p><p>Swift 自從 ABI stable 之後，只要啟用 module stability 的功能，compile 出來的 library 就會包含 .swiftinterface 的檔案。有了這個檔案，新版本就可以持續支援，不需要重 build</p><p>要支援這個也很簡單 BUILD_LIBRARY_FOR_DISTRIBUTION = YES;</p><p>把重 build 的 xcframework 放進去之後，反而出了好幾百個 error</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q-v4ux6TvKjXT2QiSHbFrA.png" /></figure><p>仔細研究了 swiftinterface 檔案內容之後，發現裡面所有的類型名稱都是 fully qualified。意思就是所有名稱都有 prefix module name。比如：</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b67aac0f537580d506534f020b3b4b5/href">https://medium.com/media/5b67aac0f537580d506534f020b3b4b5/href</a></iframe><p>如果 module name 和 class name 一樣呢?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75133082d0b6738ad69f5b5e790e2a1c/href">https://medium.com/media/75133082d0b6738ad69f5b5e790e2a1c/href</a></iframe><p>就會有和上面錯誤一樣的內容</p><p>其實錯誤訊息就有說明了，Xcode 沒辦法識別 PubNub.PubNub，因為 module 內的名稱優先序比較高。第一個 PubNub 會先找到 struct PubNub，但是底下找不到叫 PubNub 的類型</p><p>後來爬了好久的文之後，找到這個其實是超級久的 issue</p><p><a href="https://github.com/apple/swift/issues/43510">[SR-898] Unresolvable &quot;ambiguous for type lookup&quot; error when using multiple modules · Issue #43510 · apple/swift</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W83x7EvIi2uWZ7W8iu7nww.png" /></figure><p>Swift 開源三個月之後就有的 issue，這次遇到的是 variant SR-12647</p><p>目前有想到兩個解決方法</p><ol><li>不解決<br>不開啟 module stability，每次 swift 升級就重 build</li><li>想辦法重新命名 framework<br>比如 PubNub 改成 PubNubFramework，用到的地方只需要改 import 一行，其他什麼都不用改</li></ol><p>我們採用的是第二種</p><p>把所有類型放到自己的 type 底下，其實應該是解決 name collision 很好的做法，因為這樣可以保證所有的 type 前面都會有 MyName.，沒想到這樣反而造成了另外的問題</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cca25f169ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[換工作五個月，寫點東西]]></title>
            <link>https://medium.com/@jimmylevelup/%E6%8F%9B%E5%B7%A5%E4%BD%9C%E4%BA%94%E5%80%8B%E6%9C%88-%E5%AF%AB%E9%BB%9E%E6%9D%B1%E8%A5%BF-ddef5feea767?source=rss-15a224c4171d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddef5feea767</guid>
            <dc:creator><![CDATA[李昇輯]]></dc:creator>
            <pubDate>Sun, 05 Jun 2022 08:53:21 GMT</pubDate>
            <atom:updated>2022-06-05T08:53:21.885Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ua_dTwKwjsWs9j5ZBrZLAw.jpeg" /><figcaption>Houzz</figcaption></figure><p>來到 Houzz 五個月了，想在 WWDC 開始前寫點東西，記錄一下目前為止的工作成果和展望未來的目標</p><p>扣掉一開始熟悉環境的一個月，四個月期間已經完成了這些項目 (118 pr)</p><ul><li><strong>支援 iPad</strong>：讓大部分的畫面根據 size class 呈現不同樣式，包括在 iPad 上的 split, slide over。大部分是用 readable content guide 來呈現</li><li><strong>Semantic Color</strong>：把各 module 所有用到顏色的部分轉換為 semantic color，為 dark mode 作準備</li><li><strong>Localizer Lint</strong>：在原有的 Swift command line tool 上新增一個指令，可以檢查 .strings 檔案是否有以下邏輯錯誤：缺少檔案、重複的 key、缺少的 key</li><li><strong>清理不再使用的檔案</strong>：framework, nib, strings, …。一部分是手動檢查，一部分是透過第三方工具 (<a href="https://github.com/peripheryapp/periphery">periphery</a>)，一部分是自己寫一些 script</li><li><strong>清理 modular header 警告</strong>：因 Xcode 升版，產生好幾千警告，解法是把 #import “header.h” 改成 #import &lt;Module/header.h&gt;</li><li><strong>加入 </strong><a href="https://github.com/krzysztofzablocki/Inject"><strong>Inject</strong></a>：加速迭代 UI 開發</li><li><strong>拆解/建立 module</strong>：這部分是目前花最多時間和心力的，包括：</li></ul><ol><li>EntitySelector：把散落的選擇器打包成共用介面的選擇器</li><li>CallFeedback：功能獨立的部分拆出來</li><li>Models module cleanup：Model 應該只包含宣告, Codable, NSCoding。將其餘的 protocol conformance 和功能在用到的地方建立 extension</li><li>Lightbox：目前進行中的神秘項目</li></ol><p>Houzz 的兩個 app 都是保持一個月一次 release 的節奏，幾十個工程師一起在一個專案工作還很少出問題，我認為有兩個原因</p><ol><li>Mono Repository</li><li>Tuist</li></ol><p>Houzz 兩個 app 和所有 dependencies 都放在一個 repo 底下，in-house dependency 是 code，第三方是 xcframework。</p><p>比較前公司的做法，每個 lib 都有自己的 repo, podspec，再用 CocoaPods 把關聯樹建起來。當底層的 lib 要生版或是修改 api 的時候都很痛苦，只要有人沒有遵守 semantic versioning 就會出問題。Mono repo 的好處就是沒有版本問題，只有當前版本，我可以一次看到所有 call site，來評估要怎麼修改 api。</p><p>原本以為會遇到很多 git merge conflict 其實也沒有，因為自己的工作大部分時候不會和其他人有關聯，甚至根本就是不同 module。當然這也歸功於我們不 commit .xcodeproj，而是使用 Tuist。</p><p>前面提到 Module 相關的工作，大部分都要移動大量的檔案，如果是透過 Xcode UI 來設定哪個檔案要連結到哪個 target，用想的就覺得很累，更別說有多難 review 了。而透過 Tuist 的話，我只要在 Finder 移動好檔案，再在 console $Tuist generate 就完成了。我們甚至還有指令可以建立包含 interface, implementation, sample app 的 module。</p><p>目前整體而言算非常滿意，主管同事都很專業，工作也有很多可以發揮的地方。期待下次更新的時候有更多可以寫的東西</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddef5feea767" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS Locale Identifier]]></title>
            <link>https://medium.com/@jimmylevelup/ios-locale-identifier-d9dadd0147bc?source=rss-15a224c4171d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9dadd0147bc</guid>
            <category><![CDATA[locale]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[李昇輯]]></dc:creator>
            <pubDate>Fri, 22 Oct 2021 03:17:06 GMT</pubDate>
            <atom:updated>2021-10-22T03:17:06.271Z</atom:updated>
            <content:encoded><![CDATA[<p>最近在處理 Locale 的時候發現了一個意外的行為，App 內拿到的locale.identifier 不一定與系統設定的相同。</p><p>假設手機設定的語言與地區如下圖：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*Q5QLjGkdgvbT9gXFNCSAcw.jpeg" /></figure><p>語言順位是法文、繁體中文、英文，地區是日本，這時候可以拿到的 locale.identifier 應該是 fr_JP ，但實際上會由 App 支援的語言決定。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*TWXSNtE01HGav6gxvEB7GQ.png" /></figure><p>假設 App 支援繁體中文和英文，App 顯示的語言會是繁體中文（支援的最高順位），這時候拿到的 locale.identifier 會是 zh-Hant_JP，非常意外！</p><p>如果這時候把設定裡偏好的繁體中文和英文都移除，只剩下法文，這時候 App 顯示的語言會是英文（都不支援顯示開發語言），這時候拿到的 locale.identifier 會是 en_JP</p><p>得到的結論是 locale.languageCode 實際上是 App 顯示的語言，並不是使用者的偏好語言。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9dadd0147bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UITableViewController init crash with Xcode 13]]></title>
            <link>https://medium.com/@jimmylevelup/uitableviewcontroller-init-crash-with-xcode-13-a43547e84088?source=rss-15a224c4171d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a43547e84088</guid>
            <dc:creator><![CDATA[李昇輯]]></dc:creator>
            <pubDate>Thu, 21 Oct 2021 03:58:46 GMT</pubDate>
            <atom:updated>2021-10-21T03:58:46.494Z</atom:updated>
            <content:encoded><![CDATA[<p>最近在測試 Xcode 13 build 的結果時，意外發現了 crash：</p><pre>Terminating app due to uncaught exception &#39;NSInternalInconsistencyException&#39;, reason: &#39;UIViewController is missing its initial trait collection populated during initialization. This is a serious bug, likely caused by accessing properties or methods on the view controller before calling a UIViewController initializer. View controller: &lt;UITableViewController: 0x10be51b70&gt;&#39;</pre><p>Crash 發生時，正要 present 一個包裝在 UINavigationController 的 UITableViewController，實作如下：</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a01abb9d25956383d13e26202b8feea7/href">https://medium.com/media/a01abb9d25956383d13e26202b8feea7/href</a></iframe><p>從錯誤訊息來看滿奇怪的，他寫的是 init 呼叫的時候發生錯誤，不過這頁是常用功能，以前也沒有遇到問題，寫法應該是沒問題。不過先來看一下 SettingsViewController 的 init</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0c52d862360a8affe404effb55684c1/href">https://medium.com/media/d0c52d862360a8affe404effb55684c1/href</a></iframe><p>因為專案環境滿複雜的，又有混合編譯 Obj-C，為了釐清問題，開一個新專案只測試 present，並且把 @objc 的部分都拿掉，確定也可以重製 crash。</p><p>接下來就來擬定測試計畫，因為不確定問題發生的原因，把目前所想到可能影響的變因都列出來，並測試所有組合</p><ul><li>Xcode 版本 (13, 12.5)</li><li>iOS 版本 (15, 14.5)</li><li>superclass (UITableViewController, UIViewController)</li><li>init 類型 (convenience/designated 搭配 有/無 label)</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eea3a3007eba010d15c7cb73d72803f3/href">https://medium.com/media/eea3a3007eba010d15c7cb73d72803f3/href</a></iframe><p>把上面的組合測試過之後，結果如下：綠色表示通過、紅色代表一開始遇到的 crash，黃色是測試過程中發現警告訊息</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*asKjH-SGUPhakt-vhVYq3A.png" /></figure><p>黃色那個組合 Xcode 的警告訊息是：</p><pre>[Assert] UIViewController is missing its initial trait collection populated during initialization. This is a serious bug, likely caused by accessing properties or methods on the view controller before calling a UIViewController initializer. View controller: &lt;UITableViewController: 0x7fedb780b480&gt; Set a symbolic breakpoint on UIViewControllerMissingInitialTraitCollection and check the backtrace to see what&#39;s causing this. This will become an assert in a future version.</pre><p>從 Xcode 12.5 給的警告訊息推論，在 Xcode 13 遇到的 crash 應該是 assert 失敗，而 assert 只會影響到 debug build，最後要上架的 release build 應該沒有影響。從 Swift 語法的角度來看，原本的實作也沒有問題。</p><p>搜尋 Stackoverflow 上看看有沒有類似的情況，只有找到一篇討論</p><p><a href="https://stackoverflow.com/questions/69092599/xcode-13-beta-5-error-uiviewcontroller-is-missing-its-initial-trait-collection">Xcode 13 beta 5 error: UIViewController is missing its initial trait collection populated during initialization</a></p><p>他的情況也是 Xcode 13 + UITableViewController + convenience init</p><p>目前的結論是先不處理，不過以後會遠離 UITableViewController。現在有了 DiffableDataSource 和 UICollectionView，自己建一個 list view 再加到 vc 上面也沒幾行 code。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a43547e84088" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PropertyWrapper Tricks]]></title>
            <link>https://medium.com/@jimmylevelup/propertywrapper-tricks-6c8e14069131?source=rss-15a224c4171d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c8e14069131</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[property-wrapper]]></category>
            <dc:creator><![CDATA[李昇輯]]></dc:creator>
            <pubDate>Wed, 20 Nov 2019 05:25:37 GMT</pubDate>
            <atom:updated>2019-11-20T05:25:37.162Z</atom:updated>
            <content:encoded><![CDATA[<p>最近 app 想要支援多帳號登入，很多資料需要重新規劃儲存方式。其中想分享的是存在 UserDefaults 的資料要怎麼重新定義才不需要改太多程式碼。</p><p>假設我們正在做聊天軟體，有一個使用者設定是要不要上傳原始品質的圖片，如果是連到公司站，就保留原始品質；如果連到自己的伺服器，就壓縮再上傳避免把硬碟塞爆。現在這個 Bool 設定直接存在 UserDefaults (這裡用到的 @UserDefault 和 <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0258-property-wrappers.md#user-defaults">SE-0258 Property Wrapper</a> 裡面舉的例子是一樣的，有興趣的話可以點進去看 proposal)</p><pre>enum UserSettings {<br>  @UserDefault(key: &quot;preserve_image_quality&quot;, defaultValue: false)<br>  static var preserveImageQuality: Bool<br>}</pre><p>現在這個 Bool 每個登入的帳號都必須存一個，如果又想要保留 UserSettings.preserveImageQuality 的呼叫方式要怎麼做呢？</p><p>因為 UserDefaults 是一個 key/value pair 的結構，只要我可以幫每個使用者產生出獨一無二的 key，我就可以把這些東西全部存到 UserDefaults 裡面了。我們可以把使用者的識別碼串到 key 裡面</p><pre>&quot;\(Defaults.currentAccount.id)_preserve_image_quality&quot; // 新的 key</pre><p>這個新的 key pattern 可能需要用在很多 UserSettings 裡面，我們一樣用 Property Wrapper 來避免重複 boilerplate code</p><pre>@propertyWrapper<br>struct AccountDefault&lt;T&gt; {<br>  let key: String<br>  let defaultValue: T</pre><pre>  private var defaultsKey: String {<br>    &quot;\(Defaults.currentAccount.id)_\(key)&quot;<br>  }</pre><pre>  var wrappedValue: T {<br>    get {<br>      UserDefaults.standard.object(forKey: defaultsKey) as? T ?? defaultValue<br>    }<br>    set {<br>      UserDefaults.standard.set(newValue, forKey: defaultsKey)<br>    }<br>  }<br>}</pre><p>利用一個 computed property defaultsKey 讓每次 get/set 拿到的 key 都是目前的登入帳號串成的。現在 UserSettings 裡面就可以用 AccountDefault 改寫了。</p><pre>enum UserSettings {<br>  @AccountDefault(key: &quot;preserve_image_quality&quot;, defaultValue: false)<br>  static var preserveImageQuality: Bool<br>}</pre><p>唯一改動的地方就是把 UserDefault 改成 AccountDefault。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c8e14069131" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TestFlight App 一直 crash]]></title>
            <link>https://medium.com/@jimmylevelup/testflight-app-%E4%B8%80%E7%9B%B4-crash-f3baf2b3953b?source=rss-15a224c4171d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3baf2b3953b</guid>
            <category><![CDATA[testflight]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[李昇輯]]></dc:creator>
            <pubDate>Thu, 14 Nov 2019 03:47:04 GMT</pubDate>
            <atom:updated>2019-11-14T05:22:23.686Z</atom:updated>
            <content:encoded><![CDATA[<p>最近遇到神奇的 crash，QC 回報說登入按鈕一點就 crash。</p><p>經過漫長的測試和等待 TestFlight 處理之後，得到的結論是把 bitcode 關掉。</p><p>在蘋果的 <a href="https://help.apple.com/xcode/mac/current/#/devbbdc5ce4f">What is App Thinning</a>? 裡面有關 bitcode 的部分。</p><blockquote>“Bitcode is an intermediate representation of a compiled program. Apps you upload to App Store Connect that contain bitcode will be compiled and linked on the App Store. Including bitcode will allow Apple to re-optimize your app binary in the future without the need to submit a new version of your app to the App Store.”</blockquote><p>Apple 會在後台改你的 app，可能剛好遇到 Apple 演算法調整的更為激進，剛好就弄壞了。</p><p>這次找問題的過程中作得很混亂，覺得有一些可以改進的地方：</p><p><strong>測試的 build 應該另外開 branch。</strong>不要讓測試的暫時修改污染 master，尤其是 xcproj 裡面的 config 開開關關製造很多 commit 業障。</p><p><strong>從之前正常的 commit 重 build。</strong>先確認方法是正確的，再來做夾板測試，避免浪費時間作多餘的測試。</p><p><strong>確認環境沒有問題</strong>。這次遇到的問題是 Apple 出問題，平常根本不會去想他可能會壞掉，所以最後才懷疑到他身上。使用其他服務也是一樣，可以先驗證服務還是正確運作，而且驗證不需要花很多時間，又可以免掉後面的其他測試。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3baf2b3953b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>