<?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 Leon Hsieh on Medium]]></title>
        <description><![CDATA[Stories by Leon Hsieh on Medium]]></description>
        <link>https://medium.com/@chengen?source=rss-f721635a3ea4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Cwx8QY_Nu9exsgdD.</url>
            <title>Stories by Leon Hsieh on Medium</title>
            <link>https://medium.com/@chengen?source=rss-f721635a3ea4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 20:44:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chengen/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[iPhone 8 iOS13的鍵盤UI更新延遲問題]]></title>
            <link>https://chengen.medium.com/iphone-8-ios13%E7%9A%84%E9%8D%B5%E7%9B%A4ui%E6%9B%B4%E6%96%B0%E5%BB%B6%E9%81%B2%E5%95%8F%E9%A1%8C-5a8190db0e09?source=rss-f721635a3ea4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a8190db0e09</guid>
            <category><![CDATA[autolayout]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[keyboard-layout]]></category>
            <category><![CDATA[keyboard]]></category>
            <dc:creator><![CDATA[Leon Hsieh]]></dc:creator>
            <pubDate>Thu, 16 May 2024 07:10:01 GMT</pubDate>
            <atom:updated>2024-05-16T07:10:01.129Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/475/0*3NxNRZwaXxcQqIK0" /></figure><p>嗯，沒錯，是iPhone8 iOS13.1.1呢！<br>由於維護的專案仍需支援iOS13, 因此勢必得找一台搭載iOS13的iPhone來進行測試。</p><p>在縮放鍵盤時，最下面那行的「#+=」、「,」、「.」這三個按鈕總是會慢個0.幾秒才會顯示文字。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*sGyo7TaBQmqEd9oMFSrQ5A.gif" /></figure><p>將符號替換成字串後更神奇了，在更新鍵盤畫面時，UIButton上的UIButtonLabel會直接被拉伸。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*kyDkUF5CEApeOZMJKseVCQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mUkbJDCExWEiwadpXDt9Gw.png" /></figure><p>因為每排按鈕都是放在StackView中，讓系統幫我們自動縮放寬度，<br>而最下面那排按鈕因為寬度不一，因此他們的約束都有設定從1:1到1.5:1不等的比例。</p><p>由此幾乎可以確定是AutoLayout在設定比例時出了，而在為按鈕固定寬度後，問題也隨之消失。</p><p>在套用解決方案前，也需要考慮該解決方案的影響範圍：</p><ol><li>需要維持按鈕的既有寬度，避免影響到其他機型上的畫面配置</li><li>如果將按鈕的寬度固定，在其他尺寸的螢幕上可能會有潛在的畫面配置問題，使用上要小心</li><li>須考量螢幕方向的問題，水平or垂直</li><li>目前只能確定在iPhone8 iOS13.1.1上會有問題，至於是iOS的問題，或是iPhone的問題尚無法確定，且當下沒有其他iOS版本的iPhone8實機，或是安裝iOS13的其他機型能進行交叉比對</li></ol><p>在這些考量下，由於實際上無法確定這是iPhone8 SOC處理能力的問題，還是iOS13.1的問題，因此只要是iPhone8或iOS13 ，都會更新這三個按鈕的約束：</p><pre>if UIDevice.modelName.contains(&quot;iPhone 8&quot;) || UIDevice.current.systemVersion.contains(&quot;13.&quot;){<br>  //iPhone 8在縮放鍵盤時，最下排按鈕的AutoLayout計算會出現問題，改用固定寬度<br>  print(&quot;You&#39;re using an iPhone8 or iOS13 device, set fix width for bottom keys to prevent Autolayout issue&quot;)<br>  let buttonHeight: CGFloat = 40<br>  var buttonWidth:CGFloat = buttonHeight//預設的寬高比為1:1,套用預設按鈕高度<br>  symbolKeyboardBtn.removeConstraints(symbolKeyboardBtn.constraints)<br>  commaKeyBtn.removeConstraints(commaKeyBtn.constraints)<br>  periodKeyBtn.removeConstraints(periodKeyBtn.constraints)<br>  //如果是垂直，將另個按鈕的寬度作為基礎進行縮放<br>  if isLandscape {<br>    buttonWidth = upperBtn.frame.width<br>  }<br>  //#+=號按鈕的寬高比為1:1.2<br>  symbolKeyboardBtn.heightAnchor.constraint(equalToConstant: buttonHeight).isActive = true<br>  symbolKeyboardBtn.widthAnchor.constraint(equalToConstant: buttonWidth*1.2).isActive = true<br>  //逗號按鈕的寬高比為1:1            <br>  commaKeyBtn.heightAnchor.constraint(equalToConstant: buttonHeight).isActive = true<br>  commaKeyBtn.widthAnchor.constraint(equalToConstant: buttonWidth).isActive = true<br>  //句號按鈕的寬高比為1:1<br>  periodKeyBtn.heightAnchor.constraint(equalToConstant: buttonHeight).isActive = true<br>  periodKeyBtn.widthAnchor.constraint(equalToConstant: buttonWidth).isActive = true<br>}</pre><p>註：UIDevice.modleName並不在原生函式庫中，請參考</p><p><a href="https://stackoverflow.com/questions/26028918/how-to-determine-the-current-iphone-device-model/26962452#26962452">How to determine the current iPhone/device model?</a></p><p>套用解法後，原本有問題的按鈕都能即時更新了！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*V-LK64FZWuOcWMLbc_ttpQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a8190db0e09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to prevent a textField from being edited but still be able to move cursor around in Swift?]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/how-to-prevent-a-textfield-from-being-edited-but-still-be-able-to-move-cursor-around-in-swift-fda3cc5f9ea4?source=rss-f721635a3ea4------2</link>
            <guid isPermaLink="false">https://medium.com/p/fda3cc5f9ea4</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[textfield]]></category>
            <category><![CDATA[uikit]]></category>
            <dc:creator><![CDATA[Leon Hsieh]]></dc:creator>
            <pubDate>Tue, 23 Apr 2024 14:20:45 GMT</pubDate>
            <atom:updated>2024-04-24T04:48:07.165Z</atom:updated>
            <content:encoded><![CDATA[<p>How to prevent a textField been edited but still can move cursor around?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*SdnrnHYBlKE3M6WdyTNybQ.png" /></figure><p>Say, you need to create a textField for preview only, the easiest way is just disable it’s isEnable or isUserInteractionEnabled parameter, so that you can prevent it from editing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*-3HRXLTNIyIyKyUzJ3W3Hw.png" /></figure><p>But this solution can&#39;t handle the scenario of clipped text , which means users will unable to preview texts that out of range, so we need to try another way.</p><p>Inherits the <strong>UITextFieldDelegate</strong>, and implements shouldChangeCharactersIn method, we can specify a textField can be changed characters or not by return true or false</p><p>If shouldChangeCharactersIn returns false, the textField will have limited interaction but editing.<br>If shouldChangeCharactersIn returns true, the textField can be edited</p><pre>//consider specified a tag if you have multi textFields in same view controller<br>private let previewTextFieldTag = 1<br>inputTextField.tag = inputTextFieldTag<br><br>previewTextField.delegate = self<br><br>extension YourVC: UITextFieldDelegate {<br>     func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -&gt; Bool {<br>      guard textField.tag == inputTextFieldTag else {<br>            print(&quot;Forbidden to edit previewTextField&quot;)<br>            return false<br>        }<br>     }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fda3cc5f9ea4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/how-to-prevent-a-textfield-from-being-edited-but-still-be-able-to-move-cursor-around-in-swift-fda3cc5f9ea4">How to prevent a textField from being edited but still be able to move cursor around in Swift?</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fix Invalid Bundle & CFBundleIdentifier Collision. issue when Archiving Xcode project]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/fix-invalid-bundle-cfbundleidentifier-collision-issue-when-archiving-xcode-project-436385548d08?source=rss-f721635a3ea4------2</link>
            <guid isPermaLink="false">https://medium.com/p/436385548d08</guid>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[archive]]></category>
            <dc:creator><![CDATA[Leon Hsieh]]></dc:creator>
            <pubDate>Thu, 20 Jul 2023 02:04:29 GMT</pubDate>
            <atom:updated>2023-07-20T15:10:29.212Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m currently working on a iOS app, the project contains following product:<br>iOS App product: AppName<br>Custom keyboard: MyKeyboard<br>and use a framework: MySDK.</p><p>Which means I have two targets, and the framework is set to Embed &amp; Sign for both of targets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/149/1*Yzxkf45-Kj_gLK4VpLW1Sg.png" /><figcaption>First target is iOS App, second is MyKeyboard</figcaption></figure><p>Let’s go back to error message.</p><figure><img alt="The error looks like this." src="https://cdn-images-1.medium.com/max/744/1*KMQJUy2I7CjqfYJwsSk2Wg.png" /></figure><blockquote><em>Asset validation failed (90205)<br>Invalid Bundle. The bundle at ‘AppName.app/PlugIns/MyKeyboard.appex’ contains disallowed nested bundles.</em></blockquote><blockquote><em>Asset validation failed (90206)<br>Invalid Bundle. The bundle at ‘AppName.app/PlugIns/MyKeyboard.appex’ contains disallowed file ‘Frameworks’.</em></blockquote><blockquote><em>Asset validation failed (90685)<br>CFBundleIdentifier Collision. There is more than one bundle with the CFBundleIdentifier value ‘com.company.MySDK’ under the iOS application ‘AppName.app’.</em></blockquote><p>It means that there are repeated bundle identifier in this project, and MyKeyboard contains a disallowed file: Frameworks, the Frameworks folder is generated by embed setting (Target/General/Frameworks, Libraries, and Embedded Content).</p><p>So you only need to change the embed setting of the target that contains disallowed file, or contains disallowed nested bundles ( check if something exist in both of your targets and set to embed) to Do Not Embed, and the error should be dismissed.</p><p>Note: I’m not sure this a final answer or just a workaround since not all function is implemented to ‘MyKeyboard’ at current stage.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=436385548d08" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/fix-invalid-bundle-cfbundleidentifier-collision-issue-when-archiving-xcode-project-436385548d08">Fix Invalid Bundle &amp; CFBundleIdentifier Collision. issue when Archiving Xcode project</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[App上架時的一些小瑣事]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/app%E4%B8%8A%E6%9E%B6%E6%99%82%E7%9A%84%E4%B8%80%E4%BA%9B%E5%B0%8F%E7%91%A3%E4%BA%8B-313181281b8c?source=rss-f721635a3ea4------2</link>
            <guid isPermaLink="false">https://medium.com/p/313181281b8c</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[app-store]]></category>
            <category><![CDATA[app-submission]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Leon Hsieh]]></dc:creator>
            <pubDate>Fri, 10 Jun 2022 17:23:21 GMT</pubDate>
            <atom:updated>2022-06-10T17:34:53.912Z</atom:updated>
            <content:encoded><![CDATA[<p>為什麼App的預覽圖片、影片總是不給上傳？</p><p>這是我第一次跑App的上架流程時遇到的問題，順道發篇文留個紀錄，<br>剛好在2022 WWDC的尾聲（6/10下午）提出申請。</p><p>如果你需要完整上架流程，可以參考彼得潘最新的這篇：</p><p><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E5%B0%87-ios-app-%E9%80%81%E5%AF%A9%E4%B8%8A%E6%9E%B6%E5%88%B0-app-store-2be449824ae2">將 iOS App 送審上架到 App Store</a></p><h4>App 預覽和截圖</h4><p>在<a href="https://appstoreconnect.apple.com/">App Store Connect</a>頁面中，我們需要提供App的預覽圖給Apple審核才行（影片則是可有可無）</p><p>一般而言，透過模擬器內建的截圖＆錄影功能，取得App的畫面較為方便。</p><p>但如果我們把直接將模擬器產出的截圖上傳到App預覽窗格中，會顯示「影像不得含有Alpha色頻或透明度」的錯誤訊息。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cM6Gkq0nuhg26t3rdIdkWw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*vuQcxP54mQVHnqVcwciwXg.png" /></figure><p>這是因為使用有劉海的模擬器進行截圖時，瀏海的部分會自動變成透明的，因此出現了剛剛提到的錯誤訊息，因此我們處理透明度的部分。</p><p>將原本左邊帶有透明度的圖檔，轉換成右邊沒有透明度的版本才能上傳。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*xpu9_CqlvZKK23XcFpGpwA.png" /></figure><p>轉換的方式：<br>用預覽程式開啟→檔案→輸出→取消勾選Alpha<br>如果沒有出現「Alpha」的勾選方塊，就代表該圖可以上傳了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/0*Mhtj55bFtWO3MkRg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/0*8OdLLSlPsPA5L2D3" /><figcaption>左：帶有Alpha Channel的PNG，右：沒有Alpha Channel的PNG</figcaption></figure><h4>上傳預覽影片</h4><p>以6.5吋裝置為例，模擬器錄下的mp4影片解析度是1242 × 2688，</p><p>對照官方的表格，我們得提供886 x 1920解析度的影片給Apple審核才行，因此得對影片進行編輯。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*jdSfEtYjwwvqadDLho0mWw.png" /><figcaption>可以透過<a href="http://help.apple.com/itunes-connect/developer/#/dev910472ff2">下圖的「進一步了解」</a>連結訪問規格說明頁面</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*Ve3stiyruayD6kPU_EM5fA.png" /></figure><p>雖然QuickTime可以將影片轉換為1080p，但是實測後，產出的解析度會是888 x 1920，不符合886 x 1920 px的規範，所以也無法上傳（沒錯，就2px)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*62hQXnDM_HKHpvwM6w5yUQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*QA1YNjmp1BlX1i3VqbZCGA.png" /></figure><p>因此得使用如iMovie, Premiere, AfterEffect等影音編輯軟體，新建一個886 x 1920像素的專案，丟入影片手動轉檔才行。</p><p>另外，在<a href="https://stackoverflow.com/questions/57209598/why-is-my-app-store-connect-app-preview-the-wrong-size">這篇Stack Overflow</a>中有提到，也可以使用ffmpeg幫影片進行轉檔</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*0594oLY8FCfYSaVBIgcbcg.png" /></figure><p>歡迎自行在家測試</p><h4>電話欄位總是出現格式錯誤？</h4><p>在App審查資訊欄位中，左邊的「登入資訊欄位」是如果上架的App有部分功能需要用戶登入才需勾選「需要登入」方塊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*mreufRS_K7hX_-7-7fa3jw.png" /></figure><p>「聯絡人資訊欄位」則是必填的，其中電話欄位必須要有國碼：</p><p>比如+886–1234567890、+886 1234567890、+8861234567890，如果只寫0922123456就會出現格式錯誤。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*2JMx_QRQVPzUvdby_KE3mA.png" /></figure><p>因為App進入審查階段，接下來就是等回覆了，本篇文章就分享到這邊。</p><p>謝謝閱讀，如果你覺得內容有幫助，不仿點幾下拍手讓我知道！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=313181281b8c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/app%E4%B8%8A%E6%9E%B6%E6%99%82%E7%9A%84%E4%B8%80%E4%BA%9B%E5%B0%8F%E7%91%A3%E4%BA%8B-313181281b8c">App上架時的一些小瑣事</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用appendPathComponent時，出現%3F網址錯誤]]></title>
            <link>https://chengen.medium.com/%E4%BD%BF%E7%94%A8url-appendpathcomponent%E5%87%BA%E7%8F%BE-3f%E7%9A%84%E5%95%8F%E9%A1%8C-713b34cb7b05?source=rss-f721635a3ea4------2</link>
            <guid isPermaLink="false">https://medium.com/p/713b34cb7b05</guid>
            <category><![CDATA[swif]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Leon Hsieh]]></dc:creator>
            <pubDate>Thu, 02 Jun 2022 18:04:44 GMT</pubDate>
            <atom:updated>2022-06-02T18:06:07.729Z</atom:updated>
            <content:encoded><![CDATA[<p>在進行HTTP Request時，一般都會設定一個baseURL，按照需求擴充出需要的request網址。</p><p>以movieglu為例，他的baseURL是https://api-gate2.movieglu.com/</p><p>要取得目前有上映電影，就會用到getFilmsNowShowing 這個GET method，而他的request URL是filmsNowShowing/?n=10</p><p>理論上網址應該是https://api-gate2.movieglu.com/filmsNowShowing/?n=10</p><p>如果用URL.appendPathComponent 來擴充URL，那麼得到的網址會是：<br><a href="https://api-gate2.movieglu.com/filmsNowShowing/%3Fn=10">https://api-gate2.movieglu.com/filmsNowShowing/%3Fn=10</a></p><p>原本的/?n=10被<a href="https://api-gate2.movieglu.com/filmsNowShowing/%3Fn=10">/%3Fn=10</a>取代，</p><p>這是因為在url格式中，?會作為query String的分隔號使用，</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*QFbhjMT_-_mAmrZdy1oUjw.png" /></figure><p>因此得用其他方式來擴充：URLComponents或 URL(string: , relativeTo:)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb804568df3118431961375452bf470c/href">https://medium.com/media/fb804568df3118431961375452bf470c/href</a></iframe><p>參考資料：</p><ul><li><a href="https://stackoverflow.com/questions/43643879/swift-url-appendpathcomponent-replaces-with-3f">Swift URL appendPathComponent replaces ? with %3F</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E4%BD%BF%E7%94%A8-baseurl-urlcomponents-urlqueryitem-%E7%94%A2%E7%94%9F-url-1e4539a33a89">使用 baseURL，URLComponents &amp; URLQueryItem 產生 URL</a></li><li><a href="https://dafu1231.medium.com/swift%E5%BB%BA%E7%AB%8Burl-dec8a26d794e">Swift建立URL</a></li></ul><p>ㄒ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=713b34cb7b05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift-如何取得ISO 8601 格式的時間資訊]]></title>
            <link>https://chengen.medium.com/swift-%E5%A6%82%E4%BD%95%E5%8F%96%E5%BE%97iso-8601-%E6%A0%BC%E5%BC%8F%E7%9A%84%E6%99%82%E9%96%93%E8%B3%87%E8%A8%8A-afe758a0cf20?source=rss-f721635a3ea4------2</link>
            <guid isPermaLink="false">https://medium.com/p/afe758a0cf20</guid>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Leon Hsieh]]></dc:creator>
            <pubDate>Thu, 02 Jun 2022 08:22:08 GMT</pubDate>
            <atom:updated>2022-06-02T08:22:08.949Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*_YFyIkrAhJbUL11pskcV6A.png" /></figure><p>在Swift 5中，如果開發的iOS目標版本是11.0+，mac os版本10.13+的話，<br>只要調用ISO8601DateFormatter ，以及<br>withInternetDateTime、withFractionalSeconds ，就可以取得符合ISO 8601格式的時間資訊：yyyy-mm-ddThh:mm:ss.sssZ</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff0cc30ab79b4d0c491100965d1c4874/href">https://medium.com/media/ff0cc30ab79b4d0c491100965d1c4874/href</a></iframe><p>參考：</p><ul><li><a href="http://nsdateformatter.com/#examples">NSDateFormatter.com - Live Date Formatting Playground for Swift</a></li><li><a href="https://stackoverflow.com/questions/28016578/how-can-i-parse-create-a-date-time-stamp-formatted-with-fractional-seconds-utc">How can I parse / create a date time stamp formatted with fractional seconds UTC timezone (ISO 8601, RFC 3339) in Swift?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afe758a0cf20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[用Realm製作To Do List App: Part2]]></title>
            <link>https://chengen.medium.com/%E7%94%A8realm%E8%A3%BD%E4%BD%9Cto-do-list-app-part2-5f577dac23d?source=rss-f721635a3ea4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f577dac23d</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios-app-developers]]></category>
            <category><![CDATA[realm]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Leon Hsieh]]></dc:creator>
            <pubDate>Wed, 16 Feb 2022 13:13:50 GMT</pubDate>
            <atom:updated>2022-02-16T13:13:50.350Z</atom:updated>
            <content:encoded><![CDATA[<p>繼上一篇文章：<a href="https://chengen.medium.com/%E7%94%A8realm%E8%A3%BD%E4%BD%9Cto-do-list-app-part1-915b3fd7aa6c?source=your_stories_page----------------------------------------">用Realm製作To Do List App: Part1</a> <br>這篇會完成的功能有：</p><ul><li>將選擇的row列印出來</li><li>為每個選項都加入Checkbox</li><li>增刪待作事項</li></ul><h4><a href="https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614877-tableview">didSelectRowAt</a></h4><p>為了將被點選的row列印出來（或是對被點選的row進行任何動作）<br>都會用到tableView(_:didSelectRowAt:)這個常見的method。</p><pre><strong>func</strong> tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {<br>-code-<br>}</pre><p>因此只要在-code-的地方加入print(lists[indexPath.row])即可。</p><h4>Checkbox</h4><p>在Storyboard介面，點開Cell物件的Accessory下拉清單，會看到系統提供內建的Checkmark。</p><p>在預設狀態下，待作清單是不會有Checkmark的，所以接著要把勾選Checkmark的動作加入代碼中。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*RQdjk2duCoAReo3VWflTNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*hg3obUBFUGSVqZmRQod0cQ.png" /></figure><p>回到剛剛的didSelectRowAt區塊，我們要在這裡，為<strong><em>被選擇的row</em></strong>加入checkmark。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*Wh2PxYdRXc1_QS99l7Xw5A.png" /></figure><p>被選擇的row在上一篇文中有用過，就是<a href="https://developer.apple.com/documentation/uikit/uitableview/1614983-cellforrow">cellForRow(at:)</a> 這個method，<br>而checkmark是位在Accessory裡面，所以從accessoryType選擇.checkmark</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*iOWTYxU2YmKgQP1iNFKjMA.png" /></figure><p>也就是幫tableView中，位於index path的cell，加入一個accessoryType: checkmark</p><pre>tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark</pre><p>此時如果跑一次模擬器會發現，點擊待作事項後的確出現checkmark了，再次點擊卻無法取消，因此要加入判斷該cell是否被點選的if else代碼。</p><pre><strong>if</strong> tableView.cellForRow(at: indexPath)?.accessoryType == .checkmark {<br>tableView.cellForRow(at: indexPath)?.accessoryType = .none<br>} <strong>else</strong> {<br>tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark<br>}</pre><h4>新增待作事項</h4><p>到目前為止的待作事項內容都是寫死的，所以先從新增待作事項開始。在Storyboard視窗，加入Button物件到導行列的右側，System Item選擇Add</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*N-I2iFX4GAvhtQ0bRfeXlA.png" /></figure><p>也為它新增一個IBAction，Type選擇UIBarButtonItem。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*3pC5XGBM7_4BzX-s-8J1Xg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*VSflNPf-xjX_hB_0EyPTYQ.png" /></figure><p>除了新增鈕外，也會需要一個放置文字輸入框、為新待作事項命名（或其他功能）的地方</p><h4><a href="https://developer.apple.com/documentation/uikit/uialertcontroller">UIAlertController</a></h4><p>這邊選擇使用UIAlertController來放置Text Field。</p><p>在剛剛的AddButton IBAction內設置UIAlertController，選擇帶有title、message、preferredStyle的properties進行初始化。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*IgsdO8nbInRxGg_7QDn4fA.png" /></figure><p>title可以寫「加入新事項」，message留空，preferredStyle則是預設的alert</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*F1MJzJeYCt30AhpGF94TRw.png" /></figure><h4><a href="https://developer.apple.com/documentation/uikit/uialertaction">UIAlertAction</a></h4><p>有了控制器UIAlertController，還要定義點擊alert視窗內按鈕後，程式要執行什麼動作？<br>這就需要UIAlertAction，我們使用<a href="https://developer.apple.com/documentation/uikit/uialertaction/1620097-init">(title:style:handler:)</a>初始器。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*uxz5GD8L0X9UNAbYeXEpRg.png" /></figure><p>title是按鈕顯示的文字，輸入Add Item。<br>style定義按鈕樣式，使用.default預設即可。<br>handler點選後鍵入Enter，讓它展開成closure，將參數設為(action)<br>內容可以寫個 print(“Sucess Add New Item”) 讓我們知道正確執行</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*N2hRsrOSayAl3eV4xcm_Eg.png" /><figcaption>當按下UIAlert內的”Add Item”按鈕後，將會執行的內容</figcaption></figure><p>設定好UIAlertController及UIAlertAction後，還得讓他們執行及顯示。</p><p>先實作執行的部分，使用<a href="https://developer.apple.com/documentation/uikit/uialertcontroller/1620094-addaction">addAction method</a>，呼叫UIAlertController的addAction，attach對象為閉包內的action。</p><p>alert.addAction(action)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*wtsVfIdwdaFlgBX0Fv5Npg.png" /></figure><p>顯示的部分，則是使用<a href="https://developer.apple.com/documentation/uikit/uiviewcontroller/1621380-present">present(_:animated:completion:)</a><br>要呈現的viewController就是alert<br>animated設成true<br>completion則是nil，因為在顯示viewController後，沒有其他動作要執行</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*1qZedJmhlC6ILfBY2YS6hA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*ZXX1JRds6Ij2IgI0axWBcQ.png" /></figure><p>這樣彈出視窗就新增好拉！</p><p>如果這篇文章的內容對你有用，不妨點個拍手讓我知道喔～感謝感謝！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f577dac23d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[那些Xcode代碼提示裡的小icon]]></title>
            <link>https://chengen.medium.com/%E9%82%A3%E4%BA%9Bxcode%E4%BB%A3%E7%A2%BC%E6%8F%90%E7%A4%BA%E8%A3%A1%E7%9A%84%E5%B0%8Ficon-658fb736b4b6?source=rss-f721635a3ea4------2</link>
            <guid isPermaLink="false">https://medium.com/p/658fb736b4b6</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[autocomplete]]></category>
            <category><![CDATA[icons]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Leon Hsieh]]></dc:creator>
            <pubDate>Thu, 09 Dec 2021 18:19:25 GMT</pubDate>
            <atom:updated>2021-12-09T18:19:25.449Z</atom:updated>
            <content:encoded><![CDATA[<p>這個困擾我許久的問題在今天終於得到解答，先前試過把關鍵字Xcode icon 拿去餵狗，搜到的都是Xcode的icon :)</p><p>這些彩色icon方塊，他 的 正 式 名 稱 是！</p><h4>Code Sense</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*n21ijtL8YoyLrHyMQt7ZGA.png" /></figure><p>Medium的版面天生不適合放小圖，所以就直接截圖了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*tZeKs8OCVjcl11SQoWPbdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*tKO8aAIPbiK92c-nMm_r0w.png" /></figure><p>原作者＆其他資源，如果這篇有幫到你就拍個手吧</p><ul><li><a href="https://stackoverflow.com/questions/6662395/xcode-intellisense-meaning-of-letters-in-colored-boxes-like-f-t-c-m-p-c-k-etc">Xcode intellisense meaning of letters in colored boxes like f,T,C,M,P,C,K,# etc</a></li><li><a href="https://github.com/ccmoret/XcodeCS">GitHub - ccmoret/XcodeCS: In Xcode this is called &quot;Code Sense&quot;. These icons are also used in symbol navigation.</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=658fb736b4b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[用Realm製作To Do List App: Part1]]></title>
            <link>https://chengen.medium.com/%E7%94%A8realm%E8%A3%BD%E4%BD%9Cto-do-list-app-part1-915b3fd7aa6c?source=rss-f721635a3ea4------2</link>
            <guid isPermaLink="false">https://medium.com/p/915b3fd7aa6c</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[to-do-list-app]]></category>
            <dc:creator><![CDATA[Leon Hsieh]]></dc:creator>
            <pubDate>Thu, 09 Dec 2021 15:06:18 GMT</pubDate>
            <atom:updated>2021-12-09T15:06:18.048Z</atom:updated>
            <content:encoded><![CDATA[<p>這篇系列文將會紀錄如何做出一款類似Microsoft To Do的待作清單App。</p><p>先用MVC的方式構建，預計之後會用MVVM重構。</p><p>文中的開發環境為Xcode13.1，模擬器建議準備iOS15及iOS13兩種版本</p><p>首先，我們新增專案後，把TARGETS-Build Settings的iOS Development Target，從iOS15.0改為iOS13.0<br>( TARGETS會覆寫PROJECT的設定，只有TARGET沒覆寫到的才會套用PROJECT的設定）</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*ufs-eZ_12Sdc-BV7R3IyVA.png" /></figure><p>接著新增一個Table View Controller，可以看到它的Outlet都已經連接好了，這樣的好處是不用在另外拉IBOutlet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*UoEs5K5LR85PUJiktOgPow.png" /></figure><p>如果想讓App直接顯示清單列表，可以把原本的View Controller刪掉</p><p>如果不小心把原本的Entry Point一同刪除，可以到Table View Controller的Attribute inspector中，確認勾選&lt;Is Initial View Controller&gt;即可。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*8lsL1k6V9ASuJfrGAY8NgQ.png" /></figure><p>因為原本的View Controller被刪掉，所以得將Storyboard中的Table View接回ViewController.swift，先將UIViewController改成UITableViewController。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*eDZWMmEetrNXgbnIxw3LLw.png" /></figure><p>回到Storyboard，選擇Assistant模式後會發現，右半部的程式碼跟我們所熟悉的不同，這是因為class還沒接上ViewController。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QMW1RL321u0AHohrNknFOQ.png" /></figure><p>只要點開Class下拉清單，選擇ViewController即可連上ViewController.swift</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3sXjdiHyjshCBynahGnkQ.png" /></figure><p>接著把Table View Cell的identifier命名為ToDoItemCell，準備給待會的ReusableCell使用。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jLE9pFZFiDma1umv4p582w.png" /></figure><h4>新增Navigator Bar</h4><p>現在的介面只有Table View，需要新增一個Navigator Bar作為搜尋列使用：<br>在Storyboard中點選View，到Editor &gt;Embed In &gt;Navigation Controller<br>（Navigation Bar是最上方的行功能列，Tab Bar則是最底端的工具列）</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*0cW5AezCM7OEwYQFfUZuCA.png" /></figure><p>接著將Navigation Item的Title命名為ToDo。</p><p>這裡要特別注意，因為Navigation Bar及Tab Bar在iOS15中都有些變動，無法透過改變Tint Color改變顏色。</p><p>因此我直接套用系統的淺/深色模式。</p><pre>// White non-transucent navigatio bar, supports dark appearance<br>if #available(iOS 15, *) {<br>    let appearance = UINavigationBarAppearance()<br>    appearance.configureWithOpaqueBackground()<br>    UINavigationBar.appearance().standardAppearance = appearance<br>    UINavigationBar.appearance().scrollEdgeAppearance = appearance<br>}</pre><p><a href="https://stackoverflow.com/questions/69111478/ios-15-navigation-bar-transparent">iOS 15 Navigation Bar Transparent</a></p><p>另外也附上官方文件</p><p><a href="https://developer.apple.com/documentation/uikit/uinavigationcontroller/customizing_your_app_s_navigation_bar">Customizing Your App’s Navigation Bar | Apple Developer Documentation</a></p><p>先從簡單的array開始，新增硬編碼作為list內容<br>let lists = [“First”, “Second”, “Third”]</p><h4>tableView</h4><p>為了要能把array的字串丟進table view中，還需要兩個methods：</p><ul><li>numberOfRowsInSection</li><li>cellForRowAt</li></ul><h4><a href="https://developer.apple.com/documentation/uikit/uitableviewdatasource/1614931-tableview">numberOfRowsInSection</a></h4><p>它能針對section來控制要顯示幾個cell，以目前而言，要讓table view產生對應字串array的cell數量，所以要讓它回傳lists.count。</p><pre><strong>func</strong> tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {<br><strong>return</strong> lists.count<br>}</pre><h4><a href="https://developer.apple.com/documentation/uikit/uitableviewdatasource/1614861-tableview">cellForRowAt</a></h4><p>它能把每個cell安插view中到指定的位置，也就是讓我們能根據array的順序放置cell，再回傳這個cell。</p><pre>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {<br><strong>return</strong> cell<br>}</pre><p>接著使用dequeueReusableCell定義cell，它會回傳一個可重複使用的table-view cell給特定的Identifier，並把該cell加進table中。<br>而Identifier就是我們剛命名的ToDoItemCell，for 次數則使用indexPath</p><pre>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {</pre><pre><strong>let</strong> cell = tableView.dequeueReusableCell(withIdentifier: “ToDoItemCell”, for: indexPath)</pre><pre> }</pre><p>設定好cell，別忘了還得加入內容[“First”, “Second”, “Third”]</p><p>以往可以用cell.textLabel?.text = lists[indexPath.row]就能完成，但是到iOS15後，官方預告未來將會棄用textLabel，取而代之的是defaultContentConfiguration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*TnUcpTtzZejM-JXnUxDk9g.png" /></figure><h4><a href="https://developer.apple.com/documentation/uikit/uitableviewcell/3601058-defaultcontentconfiguration">defaultContentConfiguration</a></h4><p>因為這個method僅適用於iOS14及更新的版本，而舊版的iOS則還只繼續使用即將被淘汰的textLabel。</p><p>所以需要判斷裝置的iOS版本，並套用defaultContentConfiguration method</p><pre><strong>if</strong> <strong>#available</strong>(iOS 14, *){<br><strong>var</strong> content = cell.defaultContentConfiguration()<br>content.text = lists[indexPath.row]<br>cell.contentConfiguration = content<br>} <strong>else</strong> {<br>cell.textLabel?.text = lists[indexPath.row]<br>}<br><strong>return</strong> cell<br>}</pre><p>到目前為止我們完成了一個硬編碼的基礎表單，它在iOS15/13的亮暗模式下應該都能正常運作，</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*FofmGmWIrbp4GGFcW9Woow.png" /></figure><p>在下一篇文中，會幫這些cell加入點選功能，以及個別的check mark。</p><p>如果這篇文章的內容對你有用，不妨點個拍手讓我知道喔～</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=915b3fd7aa6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[理解Swift的 Type System]]></title>
            <link>https://chengen.medium.com/%E7%90%86%E8%A7%A3swift%E7%9A%84-type-system-3b816eff0b14?source=rss-f721635a3ea4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b816eff0b14</guid>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Leon Hsieh]]></dc:creator>
            <pubDate>Wed, 08 Dec 2021 04:58:34 GMT</pubDate>
            <atom:updated>2021-12-08T04:58:34.607Z</atom:updated>
            <content:encoded><![CDATA[<p>在Swift的世界中，由兩種type構成：Named type &amp; Compound type。<br>從這兩種type又延伸出六個基礎type，他們分別是protocol, enum, struct, class及 tuple function。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*SQAU80i9_yUjuK8I.png" /><figcaption><a href="https://www.raywenderlich.com/7320-getting-to-know-enum-struct-and-class-types-in-swift">Credit: raywenderlich</a></figcaption></figure><h3>Named type</h3><p>named type可以自定義名稱，它包含了class, struct, enum, protocol。</p><p>比如一個取名為myClass的instance，它就有myClass的型別。</p><p>除了能自行命名的named type之外，<a href="https://developer.apple.com/documentation/swift/swift_standard_library">Swift standard library</a> 中已經定義了許多經常被使用的named type，比如int, string, array等。</p><p>在其他程式語言中被視為基礎的data type，比如用來表現數字(numbers)、字串(strings)、characters的型別，在Swift中都屬於named type ，且會用structure的方式，在<a href="https://developer.apple.com/documentation/swift/swift_standard_library">Swift standard library</a> 中定義及實作這些data type。</p><p>也因為他們是named type，你可以藉由<a href="https://docs.swift.org/swift-book/LanguageGuide/Extensions.html">Extensions</a>及<a href="https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID378">Extension Declaration</a>來擴增他們的功能，以符合自身需求</p><h3>Compound type</h3><p>compound type沒有名字，由Swift語言本身定義，它包含了function type 及tuple type。</p><p>一個compound type裡面可能會有named typer及其他compound type。比如(Int,(Int, Int)) 就包含了兩個元素：首先是named type Int ，第二個則是compound type(Int, Int)</p><p>參考來源：<br>Swift：Types<br>raywenderlich: Getting to Know Enum, Struct and Class Types in Swift</p><ul><li><a href="https://docs.swift.org/swift-book/ReferenceManual/Types.html">Types - The Swift Programming Language (Swift 5.7)</a></li><li><a href="https://www.raywenderlich.com/7320-getting-to-know-enum-struct-and-class-types-in-swift#">Getting to Know Enum, Struct and Class Types in Swift</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b816eff0b14" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>