<?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 Master-Seafood on Medium]]></title>
        <description><![CDATA[Stories by Master-Seafood on Medium]]></description>
        <link>https://medium.com/@Master-Seafood?source=rss-4f9f8a002836------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H56OuEyzYX9UI-UbsVx61w.jpeg</url>
            <title>Stories by Master-Seafood on Medium</title>
            <link>https://medium.com/@Master-Seafood?source=rss-4f9f8a002836------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 14:34:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Master-Seafood/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[什麼是static func]]></title>
            <link>https://medium.com/@Master-Seafood/%E4%BB%80%E9%BA%BC%E6%98%AFstatic-func-cc062beded53?source=rss-4f9f8a002836------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc062beded53</guid>
            <dc:creator><![CDATA[Master-Seafood]]></dc:creator>
            <pubDate>Thu, 30 Mar 2023 07:22:14 GMT</pubDate>
            <atom:updated>2023-03-30T07:22:14.969Z</atom:updated>
            <content:encoded><![CDATA[<p>在 Swift 中，static func 是一種定義在類型本身上的靜態方法。靜態方法是一種屬於類型本身的方法，而不是屬於類型的實例。<br>簡言之，可以在&quot;未建立物件&quot;的情況下，直接調用該類別的static func<br>例如：</p><pre>struct MyStruct {<br>    static func myStaticMethod() {<br>        print(&quot;This is a static method&quot;)<br>    }<br>}<br><br>MyStruct.myStaticMethod() // 輸出：This is a static methods</pre><p>在這個例子中，我們定義了一個名為 myStaticMethod() 的static func，它屬於 MyStruct 這個結構體。<br>通過 MyStruct.myStaticMethod()，我們可以直接調用這個靜態方法，而不需要先創建一個 MyStruct 的實例。<br>94這麼跩</p><p>※：需要注意的是，靜態方法只能訪問靜態成員和其他靜態方法，無法訪問實例成員和實例方法。例如：</p><pre>struct MyStruct {<br>    static var myStaticProperty = &quot;Static Property&quot;<br>    var myInstanceProperty = &quot;Instance Property&quot;<br>    <br>    static func myStaticMethod() {<br>        print(myStaticProperty) // 可以訪問靜態成員<br>        // print(myInstanceProperty) // 無法訪問實例成員<br>        // self.myInstanceMethod() // 無法訪問實例方法<br>    }<br>    <br>    func myInstanceMethod() {<br>        print(myStaticProperty) // 可以訪問靜態成員<br>        print(myInstanceProperty) // 可以訪問實例成員<br>        MyStruct.myStaticMethod() // 可以調用靜態方法<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc062beded53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[什麼是值類型/參考類型?]]></title>
            <link>https://medium.com/@Master-Seafood/%E4%BB%80%E9%BA%BC%E6%98%AF%E5%80%BC%E9%A1%9E%E5%9E%8B-%E5%8F%83%E8%80%83%E9%A1%9E%E5%9E%8B-85e937a2acb9?source=rss-4f9f8a002836------2</link>
            <guid isPermaLink="false">https://medium.com/p/85e937a2acb9</guid>
            <dc:creator><![CDATA[Master-Seafood]]></dc:creator>
            <pubDate>Thu, 30 Mar 2023 07:11:21 GMT</pubDate>
            <atom:updated>2023-03-30T07:11:21.154Z</atom:updated>
            <content:encoded><![CDATA[<p>在 Swift 中，每個變數和常數都有一個特定的類型，這個類型可以是值類型或者是參考類型。</p><p>值類型：值類型是指存儲在堆疊中的數據類型，它們通常是結構體（struct）、枚舉（enum）和基本數據類型（Int、Double、Bool 等）。值類型的實例在傳遞和賦值時，都是進行複製操作，因此在不同的變量或常量中儲存的是不同的數據，修改其中一個變量或常量的值不會影響其他變量或常量。</p><p>參考類型：參考類型是指儲存在堆（Heap）中的數據類型，通常是類別（class）和閉包（closure）。不同於值類型，它們在進行傳遞和賦值時，實際傳遞的是對該數據的引用（即指針），多個變數或常量可以引用同一個數據，並且修改其中一個變數或常量的值會影響其他變數或常量。</p><p>總體而言，區分值類型和參考類型的主要區別在於它們的複製和傳遞方式不同。值類型在賦值和傳遞時進行的是複製操作，而參考類型則是傳遞對該數據的引用，也就是指向該數據在堆中的地址。這一點在處理大量數據和多線程編程時尤其需要注意。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85e937a2acb9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SPM安裝擴充套件]]></title>
            <link>https://medium.com/@Master-Seafood/spm%E5%AE%89%E8%A3%9D%E6%93%B4%E5%85%85%E5%A5%97%E4%BB%B6-cd4cf207ff86?source=rss-4f9f8a002836------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd4cf207ff86</guid>
            <dc:creator><![CDATA[Master-Seafood]]></dc:creator>
            <pubDate>Sat, 15 Oct 2022 06:50:11 GMT</pubDate>
            <atom:updated>2022-10-15T06:50:11.602Z</atom:updated>
            <content:encoded><![CDATA[<p>SPM安裝擴充套件</p><p>乾<br>為了實現從網頁抓資料的功能<br>要安裝Alamofire</p><p>上網爬文發現要管理擴充套件<br>需要安裝cocoapod／nvm／ruby/rvm<br>裝一裝發現好像搞壞惹<br>爆氣初始化mac<br>森７７</p><p>後來發現可以直接用內建的SPM新增Alamofire<br>雖然不知道功能有沒有差異<br>但至少可以直接新增ＱＱ<br>就先來使用看看<br>並記錄一下新增擴充的方式</p><p>Xcode-File-Add Package</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zUCsLPhIMvJwOSJzTuOrtQ.png" /></figure><p>右上角輸入擴充套件的&quot;github&quot;網址<br><a href="https://links.jianshu.com/go?to=https%3A%2F%2Fgithub.com%2FAlamofire%2FAlamofire">https://github.com/Alamofire/Alamofire</a><br>例如Alamofire的網址</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1RMaAIjuFdNMwGfYkWNyaQ.png" /></figure><p>就會顯示<br>點右下角Add package就完成了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AFDDpKp2a3W7sWvVhObf0w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd4cf207ff86" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[嘗試做小說app-Part2]]></title>
            <link>https://medium.com/@Master-Seafood/%E5%98%97%E8%A9%A6%E5%81%9A%E5%B0%8F%E8%AA%AAapp-part2-f67574777b04?source=rss-4f9f8a002836------2</link>
            <guid isPermaLink="false">https://medium.com/p/f67574777b04</guid>
            <dc:creator><![CDATA[Master-Seafood]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 05:34:30 GMT</pubDate>
            <atom:updated>2022-10-12T05:34:30.671Z</atom:updated>
            <content:encoded><![CDATA[<p>09/30<br>經過兩週的努力<br>終於可以搜尋小說<br>並呈現內容<br>如下</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*xGrVL6ipzaX5BtXXkuXrPQ.gif" /></figure><p>但這API是別人做的<br>小說的連載進度不夠新<br>想自己生一個API<br>然後要加上<br>調字體/顏色/背景色<br>儲存目前章節進度/預載<br>這些功能<br>一步一步來<br>今晚就先來研究API怎ㄇ弄</p><p>10/07<br>估狗了一陣子，發現弄API好像需要牽扯到server和後端?<br>目前第一目標是把小說APP做出來<br>暫時沒空學後端</p><p>替代方案<br>第三方套件好像可以抓網頁資料<br>再來研究看看怎麼使用</p><p><strong>翻轉章節順序</strong></p><p>有時需要正序／倒序切換<br>研究一下怎麼用button控制tableView翻轉<br><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/83-%E5%88%A9%E7%94%A8-cgaffinetransform-%E7%B8%AE%E6%94%BE-%E4%BD%8D%E7%A7%BB%E5%92%8C%E6%97%8B%E8%BD%89-e061df9ed672">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/83-%E5%88%A9%E7%94%A8-cgaffinetransform-%E7%B8%AE%E6%94%BE-%E4%BD%8D%E7%A7%BB%E5%92%8C%E6%97%8B%E8%BD%89-e061df9ed672</a></p><p>tableView.transform = CGAffineTransformMakeScale(1, -1)<br>可以翻轉整個tableview<br>cell.contentView.transform = CGAffineTransformMakeScale(1, -1)<br>可以翻轉cell</p><p>但我在Button的IBAction裏面，沒辦法call cell誒？？？<br><strong>暫時解法：</strong><br>直接在cellforrowAt裡面<br>放個比較<br>餘數為０就正<br>餘數為１就倒</p><p>每次button按下就＋１<br>然後reloaddata 和tableView</p><p><strong>翻轉動畫範例</strong></p><pre>UIView.transition(with:tableView,<br>                                duration: 0.5,<br>                                options: .transitionFlipFromLeft,<br>                                animations: nil,<br>                                completion: nil)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f67574777b04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[安裝Cocoapod時遇到的安裝問題]]></title>
            <link>https://medium.com/@Master-Seafood/%E5%AE%89%E8%A3%9Dcocoapod%E6%99%82%E9%81%87%E5%88%B0%E7%9A%84%E5%AE%89%E8%A3%9D%E5%95%8F%E9%A1%8C-ec3bf0ec8339?source=rss-4f9f8a002836------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec3bf0ec8339</guid>
            <dc:creator><![CDATA[Master-Seafood]]></dc:creator>
            <pubDate>Sun, 09 Oct 2022 10:15:27 GMT</pubDate>
            <atom:updated>2022-10-09T10:15:27.419Z</atom:updated>
            <content:encoded><![CDATA[<p>想安裝第三方套件<br>讓app可以抓網頁的資料<br>於是開始研究怎麼抓資料<br>第一步就是要建置環境<br>記錄一下安裝時的問題<br>真的很搞剛</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-LVaRZtql0dXKg_PGpJm7Q.png" /></figure><p>錯誤１<br>[!] Invalid `Podfile` file: syntax error, unexpected backslash, expecting ‘}’.</p><p>podfile記事本裡面的格式不對<br>或是內容不匹配</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wrNblINe8aMRvHO36-bKng.png" /></figure><p>錯誤2<br>You might have to install separate package for the ruby development environment, ruby-dev or ruby-devel for example.</p><p>在preference的location內<br>要選command line tools<br>選完關閉xcode就可以繼續安裝ㄌ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GiLf1rHbFVzj7hKFBE4Cfg.png" /></figure><p>錯誤3<br>You may have encountered a bug in the Ruby interpreter or extension libraries.<br>Bug reports are welcome.</p><p>Ｍ１開始才會遇到的問題<br>處理方式：</p><p>終端機ＣＤ到pod install的目錄下<br>依序執行<br>1.<br>sudo arch -x86_64 gem install ffi<br>會跑一下</p><p>2.<br>arch -x86_64 pod install</p><p>安裝完後<br>就可以回頭安裝原本無法安裝的套件惹<br>如下</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iysLq7-crKuDSnN5EyvjAA.png" /></figure><p>參考資料</p><p><a href="https://www.cnblogs.com/lulushen/p/16078446.html">https://www.cnblogs.com/lulushen/p/16078446.html</a></p><p><a href="https://medium.com/adream4ever/%E4%BA%86%E8%A7%A3-cocoapods-%E8%A7%80%E5%BF%B5-%E8%A7%A3%E6%B1%BA%E5%AE%89%E8%A3%9D%E6%8C%91%E6%88%B0-c734ce7a0bab">了解 Cocoapods 觀念，解決安裝挑戰！</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec3bf0ec8339" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[嘗試做小說app-Part1]]></title>
            <link>https://medium.com/@Master-Seafood/%E5%98%97%E8%A9%A6%E5%81%9A%E5%B0%8F%E8%AA%AAapp-397247bc3d66?source=rss-4f9f8a002836------2</link>
            <guid isPermaLink="false">https://medium.com/p/397247bc3d66</guid>
            <dc:creator><![CDATA[Master-Seafood]]></dc:creator>
            <pubDate>Sat, 01 Oct 2022 17:07:13 GMT</pubDate>
            <atom:updated>2022-10-03T12:43:22.509Z</atom:updated>
            <content:encoded><![CDATA[<p>肥宅從小就喜歡看小說<br>從智慧手機流行後，特別喜歡用小說app來閱讀<br>但每次都要被小說app的廣告霸凌<br>實在是很ㄅ爽(對，我就是在臭黑貓和古燈，廣告一堆ㄇㄉ）<br>所以，想做一個可以自用無廣告的app<br>如果做得好，就能換我上架霸凌別人(?</p><p>方式一<br>從大陸開源api<br>抓簡體小說資料<br>做繁簡體轉換後再輸出／輸入</p><p>方式二</p><p>爬蟲抓包<br>再自己做成API?</p><p>肥宅很廢，方法二還不太理解<br>先做方法一練練手</p><p><strong>Step1(2022/09/14)</strong></p><p>找到了一個簡體開源的小說api<a href="https://easydoc.net/doc/45910076/WP3yrgI7/yih8gcXV"><br>https://easydoc.net/doc/45910076/WP3yrgI7/yih8gcXV</a><br>可以搜尋作者,標題…等資訊<br>並獲得進一步章節與小說內容</p><p><strong>Step2(2022/09/14)</strong></p><p>api內容全都是簡體<br>台灣使用者不太方便<br>我自己也懶得在搜尋小說標題時<br>多做一步簡體轉換</p><p>於是，決定將搜尋欄輸入的字串轉成簡體<br>再從api撈資料<br>撈完資料，再將資料轉成繁體呈現<br>雖然有點繞<br>但目前不知道其他更好的方法<br>先這樣幹ㄅ</p><p>抓到資料時<br>data內容是[String]<br>要靠.joined()將array轉為字串<br>才能顯示在textView</p><pre>if let url = URL(string:urlString){<br>    print(&quot;1&quot;)<br>    URLSession.shared.dataTask(with: url) { data, reponse, error in<br>        print(&quot;2&quot;)<br>        let decoder = JSONDecoder()<br>        if let data{<br>            do {<br>                let content = try decoder.decode(Contents.self, from: data)<br>                <br>                let novelContent = content.data<br>                let textString = novelContent.joined()</pre><p><strong>Step3(2022/09/15)</strong><br>可以抓到資料ㄌ <br>但不知道怎麼呈現在tableView 或tableViewControler上<br>以下先從controller開始練習</p><p>Static</p><p>摘錄“在 Swift 裡，只要在某個方法前面加上 static 關鍵字，就會使它成為是<em>屬於那個型別本身的方法</em>。”<br>其實看不太懂，先實測一下</p><p>只要加了static，即時沒有建立物件<br>也能存取屬性和方法<br>如下 let maxAge 可以存取Baby.maxAge<br>但不能存取aquariusBaby和creatAquaBaby()</p><pre>class Baby{<br>    var star:String<br>    init(star:String){<br>        self.star = star<br>    }<br>    <br>    static var maxAge = 100<br>    var aquariusBaby = Baby(star: &quot;水平&quot;)<br>    func creatAquaBaby() -&gt; Baby{<br>        return Baby(star: &quot;水平&quot;)<br>    }<br>}</pre><pre>let maxAge = Baby.maxAge</pre><p><strong>tableviewController</strong></p><p>本來寫好的static tableview<br>改成dynamic後，會報錯</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*47KRAZCOAz3Jke0pVViA6w.png" /></figure><p>估狗了一下<br>看起來是：右邊設static cell時，才能直接在storyboard中，用outlet collections直接把table裡面的cell連結成一個array<br>若右邊設為dynamic cell時，要創建一個UITableViewCell subclass給cells，並在此新增outlets</p><p>那到底要怎麼使用dynamic?<br>原來，是因為cell沒有被成功新增<br>當新增內容後，就可以成功build啦<br>如下</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5q720cDaYEXAUWVN0_JIPA.png" /></figure><h3>從 iOS 15 開始，可以使用內建 cell 樣式建議搭配 UIListContentConfiguration</h3><p>舊的感覺比較簡單，好建立</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*Sk62Oe7jcdK3cwT_mKx0Hg.png" /><figcaption>舊的cell建立和使用方式</figcaption></figure><p>新的可以自定imageSize，蠻方便ㄉ<br>然後detailText變成secondaryTextㄌ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*UBEvTmcv8q2J-PrOQhOOnw.png" /><figcaption>ＩＯＳ１４開使，新的使用方式</figcaption></figure><h3>記錄遇到的問題</h3><h3>問題一</h3><p>抓api時，url若有中文<br>需要另外轉換<br>可以用addingPercent等方式來轉換<br>不然if url=URL(....<br>會讀不出來<br>乾，卡了兩小時才發現這問題<br>記錄一下 ７８</p><h3>iOS 解碼 &amp; 編碼 JSON 的文章整理</h3><p>json文章整理</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/ios-%E8%A7%A3%E7%A2%BC-%E7%B7%A8%E7%A2%BC-json-%E7%9A%84%E6%96%87%E7%AB%A0%E6%95%B4%E7%90%86-d3f6aa7abf95">iOS 解碼 &amp; 編碼 JSON 的文章整理</a></p><p>若是網址包含 ASCII character-set 以外的字元，比方中文，則須對網址進行 URL Encoding</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/ios-16-%E7%9A%84-urlcomponents-%E5%8F%AF%E4%BB%A5%E8%87%AA%E5%8B%95%E5%B0%8D%E7%B6%B2%E5%9D%80%E9%80%B2%E8%A1%8C-url-encoding-68df08be6a25">iOS 17 的 URL 和 16 的 URLComponents 可以自動對網址進行 URL Encoding</a></p><h3>問題二</h3><p><strong>設定@IBSegueAction時<br></strong>controller物件建立時，要加上(coder:coder)，雖然不太懂為啥，但就是要加，才可以成功return controller到下個頁面，神奇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sY-0X8MQAiz8gZnRdSXwYQ.png" /></figure><h3>問題三</h3><p><strong>“Expected to decode Array&lt;Any&gt; but found a dictionary instead.”<br></strong>填[DataItem]時，系統好像會判別為 = dictionary<br>填DataItem，會被當成陣列array&lt;any&gt;</p><p>json姐包時怎麼判斷是字典還是陣列<br>之後要再複習一下<br>有點忘了</p><p>小問題紀錄</p><p>Redundant conformance<br>表示已經定義過deleagte，不用再定義一次</p><p>在tableView上加一層view物件<br>下方為新增UIActivityIndicatorView<br>直接放viewDidload就好</p><pre>//============================================<br>           //試著在table上加一層view或物件<br>        let activeIndicatorView = UIActivityIndicatorView()<br>        activeIndicatorView.frame = CGRect(x: 120, y: 200, width: 190, height: 190)<br>        activeIndicatorView.style = .large<br>        activeIndicatorView.startAnimating()<br>        <br>        self.view.addSubview(activeIndicatorView)<br>        <br>    //============================================</pre><p>如果最後抓出來的資料<br>是String的arry<br>[String]<br>可以用joined<br>把array拆開，並集合成一個string</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*6Mh01WZKxI1sWlIzLga_5Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=397247bc3d66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ARC/Reference Count/Weak var/unowned var(let)]]></title>
            <link>https://medium.com/@Master-Seafood/arc-reference-count-weak-var-unowned-var-let-7a71a6ecf591?source=rss-4f9f8a002836------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a71a6ecf591</guid>
            <dc:creator><![CDATA[Master-Seafood]]></dc:creator>
            <pubDate>Sat, 24 Sep 2022 09:05:15 GMT</pubDate>
            <atom:updated>2022-09-24T09:09:02.887Z</atom:updated>
            <content:encoded><![CDATA[<p>ARC/Reference Count/Weak var/unowned var(let)</p><p>聽說Swift用ARC機制自動管理物件的生死<br>好像有些門道<br>稍微紀錄一下</p><p><strong>名詞解釋</strong><br>ARC:Automatic Reference Count<br>reference count:維持物件生命的計數<br>reference cycle:兩個物件，相互指著，導致無法正常死亡的狀況<br>weak var:不增加reference count的變數定義方式<br>unowned var(let):和weak功能類似，但有一些差異，差異記錄於下方</p><p><strong>筆記</strong></p><p><strong>如何管理物件死活</strong></p><pre>class Seafood{<br>}<br>var cutePucy:Seafood? = Seafood()</pre><pre>cutePucy = nil</pre><p>原本有葛物件&quot;海鮮&quot;，被變數&quot;cutePucy&quot;指著，這時物件是存活的<br>如果將cutePucy設為nil<br>香噴噴的噗洗不見了<br>導致海鮮無人關注，很可憐，活不下去<br>於是就掛惹<br>大概４醬，幫海鮮ＱＱ</p><p><strong>Deinit</strong><br>提到海鮮掛掉<br>要順便記錄一下deinit<br>類似死前遺言<br>比如以下程式碼</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*PRzzoS3SCybB1TwIKRwgGA.png" /><figcaption>當噗洗不見，海鮮死掉的時候<br>會喊出遺言”海鮮可愛，海鮮務實”</figcaption></figure><p><strong>型別的屬性</strong><br>型別建立時，有時會新增一些屬性<br>例如寶寶型別內定義了屬性pet=Dog()<br>在這種情況下，若寶寶掛了，狗狗也會一起掛<br>很可憐ＱＱ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*_IuFoa609KHSK1HV5u4b4w.png" /><figcaption>引述自彼得潘的Swift程式設計入門</figcaption></figure><p><strong>reference cycle</strong><br>先看幾個程式運行的結果</p><p><em>情況一 Ａ指向Ｂ</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U_p2osfk2Olqn_DbHpKlSw.png" /><figcaption>因為cuteBaby仍指著cuteDog，所以cuteDog=nil時，不會觸發deinit</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cEa_QmOqZHvDk5eXFPPDsg.png" /><figcaption>cuteBaby = <strong>nil，這時</strong>cuteDog = <strong>nil，就會執行deinit惹</strong></figcaption></figure><p><strong><em>情況二 ＡＢ互指 （</em>reference cycle）</strong><em><br>這種情況會浪費記憶體，導致閃退</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-0v7_7oH5EmfiBmKeDQs1A.png" /><figcaption>雖然cuteBaby和cuteDog都為nil，但內部屬性仍指著對方，導致無法正常死亡，deinit不會觸發</figcaption></figure><p><strong>weak var</strong></p><p>當發生<strong>reference cycle</strong>時，就需要weak var來救場<br>如下<br>Baby型別指向dog時使用weak var<br>就不會增加reference count<br><strong>對系統來說，就沒有東西指向pet:Dog了</strong><br>此時依然能夠訪問使用Baby.pet等相關功能</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*lLCRohevPZRMSYMeBYxyxw.png" /><figcaption>這時狗狗可以順利死掉</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rjUDUzLTPCrsF9GFBpMYRw.png" /><figcaption>若寶寶自己先死也沒用，因為狗狗的owner仍指著寶寶</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*irmaakz9f2SuUmVIGbxTPw.png" /><figcaption>狗狗死後，寶寶就可以死了，所以寶寶的deinit會比較晚印出</figcaption></figure><p><strong>unowned var(let)</strong></p><p>unowned和weak類似，一樣不會增加物件的 reference count<br>差異在於<br>1.unowned指到的物件死去時，不會自動變為nil(存取死亡的非nil物件，可能造成閃退）<br>2.unowned不能宣告optional的參數（指變數與常數）<br>3.unowned可以宣告常數(let)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a71a6ecf591" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[測試不同controller & delegate]]></title>
            <link>https://medium.com/@Master-Seafood/uidocumentpickerviewcontroller-9e964449478b?source=rss-4f9f8a002836------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e964449478b</guid>
            <dc:creator><![CDATA[Master-Seafood]]></dc:creator>
            <pubDate>Sun, 18 Sep 2022 13:11:30 GMT</pubDate>
            <atom:updated>2022-09-24T08:06:12.708Z</atom:updated>
            <content:encoded><![CDATA[<p>今天測試各種形式的delegate操作</p><h3>UIDocumentPickerViewController</h3><p>使用UIDcoumentPickerViewController前<br>需要import UniformTypeIdentifiers<br>先來記錄功用<br>import之後<br>可以設定<br>要讀取／寫入的資料<br>是什麼型別<br>如下</p><p>import UniformTypeIdentifiers後<br><strong>再<br>let</strong> controller = UIDocumentPickerViewController(forOpeningContentTypes: [.jpeg, .png], asCopy: <strong>true</strong>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K39NFeufUI0od1A3ynThkw.png" /></figure><p>就可以宣告<br>若不是.jpeg, .png就不能選取</p><p>如下<br>中間和右邊不是.png檔案<br>就不能選取<br>左邊是png，所以可選<br>讚讚</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*Z7jHjoP9aHSjqfZzihWj7g.png" /></figure><h3>UIVideoEditorController</h3><p>可以選取影片檔<br>並進行編輯</p><ol><li>拉button設定IBAction<br>從bundle.path得到檔案的path<br>(關於bundle說明，可參考</li></ol><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%A6%82%E4%BD%95%E8%A3%BD%E4%BD%9C-bundle-%E5%92%8C%E8%AE%80%E5%8F%96-bundle-%E8%A3%A1%E7%9A%84%E6%AA%94%E6%A1%88-eefdb49ba16">如何製作 Bundle 和讀取 Bundle 裡的檔案</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*svAALYx9RXWRzsOnFT9TIw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*coKG72_Tpmqkuxn3zwBZkQ.png" /><figcaption>影片名稱為&quot;11&quot;</figcaption></figure><p>取得路徑名稱後<br>在VideoController的function &quot;videoEditorController&quot;中設定<br>編輯影片後<br>播放</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cItryqbLkOiBksBhdgHQ0g.png" /></figure><h3>PHPickerViewController</h3><p>從ios14開始<br>有新的相片選擇controller<br>加減摸一下ＱＱ</p><p>聽說功能是多了<br>1.多選照片<br>2.搜尋照片</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GiR0mBtjcQQajI_zgdTi9A.png" /></figure><p>使用流程</p><p>1.<br>import PhotosUI<br>才能導入PHP的delegate<br>2.<br>點擊按鈕後<br>顯示PHPicerViewController</p><p>這裡設定了delegate，當使用者選取照片後<br>會觸發delegate的function<br>(其實這裡有點陌生，意思應該是，當我present &quot;picker&quot;，picker delegate的function也會被執行吧ＱＱ)</p><pre><a href="http://twitter.com/IBAction">@IBAction</a> func choosePhoto(_ sender: Any) {<br>        var configuration = PHPickerConfiguration()<br>        configuration.filter = .images<br>        //PHPickerConfiguration 的 filter 預設為nil，代表可選擇影片＋圖片，目前我只想要圖片，所以設定.image<br>        let picker = PHPickerViewController(configuration:configuration)<br>        picker.delegate = self<br>        present(picker, animated: true)<br>        <br>        <br>    }</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e964449478b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[⭐️ 二十一點亞洲慈善撲克王大賽]]></title>
            <link>https://medium.com/@Master-Seafood/%EF%B8%8F-%E4%BA%8C%E5%8D%81%E4%B8%80%E9%BB%9E%E4%BA%9E%E6%B4%B2%E6%85%88%E5%96%84%E6%92%B2%E5%85%8B%E7%8E%8B%E5%A4%A7%E8%B3%BD-ca4bbb216b7f?source=rss-4f9f8a002836------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca4bbb216b7f</guid>
            <dc:creator><![CDATA[Master-Seafood]]></dc:creator>
            <pubDate>Sun, 04 Sep 2022 09:58:07 GMT</pubDate>
            <atom:updated>2022-09-04T09:58:07.716Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*IUMWg3PwYrrgjBExWnP1Tw.gif" /></figure><p>最近聽說柬埔寨很紅<br>趕緊跟風學一下怎麼做打牌的遊戲<br>熱身熱身，準備進軍柬埔寨博弈產業<br>壓榨小８＋９們</p><p>開始製作寫<br>先確認要做的項目</p><ol><li>&quot;拿牌&quot;後新增並顯示卡牌</li><li>隨機拿牌</li><li>名稱內若有xx則zz,可用prefix或description.contains</li><li>給電腦牌</li><li>間隔n秒 發下一張卡片</li><li>和對方比較</li><li>籌碼下注</li></ol><p>查看字串中是否有某字元或字串<br>可使用<br>hasPrefix<br>hasSuffix<br>String.description.contains(“某字元或字串”)</p><p>timer<br>var timer:Timer?<br>timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block:{<br> (timer) in<br> print(“aa”)<br>})</p><p>timer?.invalidate()</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca4bbb216b7f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[⭐️ 使用 IBOutlet，IBAction & 亂數創作有趣的 App]]></title>
            <link>https://medium.com/@Master-Seafood/%EF%B8%8F-%E4%BD%BF%E7%94%A8-iboutlet-ibaction-%E4%BA%82%E6%95%B8%E5%89%B5%E4%BD%9C%E6%9C%89%E8%B6%A3%E7%9A%84-app-a93b818b60e2?source=rss-4f9f8a002836------2</link>
            <guid isPermaLink="false">https://medium.com/p/a93b818b60e2</guid>
            <dc:creator><![CDATA[Master-Seafood]]></dc:creator>
            <pubDate>Sat, 13 Aug 2022 11:33:43 GMT</pubDate>
            <atom:updated>2022-08-13T11:33:43.009Z</atom:updated>
            <content:encoded><![CDATA[<p>石器時代<br>偶們永遠ㄉ愛</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*a8e9yl3ieZcpWok44ILwKA.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a93b818b60e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>