<?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/@lulu94eunice?source=rss-a1e3cc66fc79------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Bg-OxadkbNrJKqTpJUhQuQ@2x.jpeg</url>
            <title>Stories by ＬＵＬＵ on Medium</title>
            <link>https://medium.com/@lulu94eunice?source=rss-a1e3cc66fc79------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 09:13:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lulu94eunice/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[Web3Swift 使用筆記 1]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/web3swift-%E4%BD%BF%E7%94%A8%E7%AD%86%E8%A8%98-1-b21daab391b2?source=rss-a1e3cc66fc79------2</link>
            <guid isPermaLink="false">https://medium.com/p/b21daab391b2</guid>
            <dc:creator><![CDATA[ＬＵＬＵ]]></dc:creator>
            <pubDate>Wed, 29 Jun 2022 07:20:40 GMT</pubDate>
            <atom:updated>2022-06-29T09:33:13.976Z</atom:updated>
            <content:encoded><![CDATA[<p>Web3Swift是用於與以太坊網絡互動的iOS工具。<br>（最近因為工作需要都在看新東西，眼花撩亂😵‍💫想想好像太久沒更新了ＸＤ</p><p>首先先安裝CocoaPods</p><pre>sudo gem install cocoapods</pre><p>打開Podfile添加以下資訊</p><pre>source &#39;<a href="https://github.com/CocoaPods/Specs.git&#39;">https://github.com/CocoaPods/Specs.git&#39;</a><br>platform :ios, &#39;9.0&#39;</pre><pre>target &#39;&lt;Your Target Name&gt;&#39; do<br>    use_frameworks!<br>    pod &#39;web3swift&#39;<br>end</pre><p>之後 pod install</p><p>Carthage是一個去中心化管理，提供你建構二進制的框架（翻譯好難ＱＱ</p><pre>$ brew update<br>$ brew install carthage</pre><p>使用 Carthage 將 web3swift 整合到的 Xcode 項目中，請在的 Cartfile 中指定它。 使用 touch 命令創建一個空的 Cartfile 並打開它：</p><pre>$ touch Cartfile<br>$ open -a Xcode Cartfile</pre><p>將以下行添加到 Cartfile 並保存：</p><pre>github &quot;skywinder/web3swift&quot; &quot;master&quot;</pre><p>有興趣請看詳細內容：</p><p><a href="https://github.com/skywinder/web3swift#installation">GitHub - skywinder/web3swift: Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions.</a></p><h3>關於API</h3><h4>Preferred keys Wallet Model (Account)</h4><pre>struct Wallet {<br>    let address: String<br>    let data: Data<br>    let name: String<br>    let isHD: Bool<br>}</pre><pre>struct HDKey {<br>    let name: String?<br>    let address: String<br>}</pre><h4>Preferred ERC-20 Model</h4><pre>class ERC20Token {<br>    var name: String<br>    var address: String<br>    var decimals: String<br>    var symbol: String<br>}</pre><h3>Create Account</h3><h4>With Private Key</h4><pre>let password = &quot;web3swift&quot; // We recommend here and everywhere to use the password set by the user.<br>let keystore = try! EthereumKeystoreV3(password: password)!<br>let name = &quot;New Wallet&quot;<br>let keyData = try! JSONEncoder().encode(keystore.keystoreParams)<br>let address = keystore.addresses!.first!.address<br>let wallet = Wallet(address: address, data: keyData, name: name, isHD: false)</pre><h4>With Mnemonics Phrase</h4><pre>let password = &quot;web3swift&quot;<br>let bitsOfEntropy: Int = 128 // Entropy is a measure of password strength. Usually used 128 or 256 bits.<br>let mnemonics = try! BIP39.generateMnemonics(bitsOfEntropy: bitsOfEntropy)!<br>let keystore = try! BIP32Keystore(<br>    mnemonics: mnemonics,<br>    password: password,<br>    mnemonicsPassword: &quot;&quot;,<br>    language: .english)!<br>let name = &quot;New HD Wallet&quot;<br>let keyData = try! JSONEncoder().encode(keystore.keystoreParams)<br>let address = keystore.addresses!.first!.address<br>let wallet = Wallet(address: address, data: keyData, name: name, isHD: true)</pre><h3>Import Account</h3><h4>With Private Key</h4><pre>let password = &quot;web3swift&quot;<br>let key = &quot;L2HRewdY7SSpB2jjKq6mwLes86umkWBuUSPZWE35Q8Pbbr8wVyss124sf124dfsf&quot; // Some private key<br>let formattedKey = key.trimmingCharacters(in: .whitespacesAndNewlines)<br>let dataKey = Data.fromHex(formattedKey)!<br>let keystore = try! EthereumKeystoreV3(privateKey: dataKey, password: password)!<br>let name = &quot;New Wallet&quot;<br>let keyData = try! JSONEncoder().encode(keystore.keystoreParams)<br>let address = keystore.addresses!.first!.address<br>let wallet = Wallet(address: address, data: keyData, name: name, isHD: false)</pre><h4>With Mnemonics Phrase</h4><pre>let password = &quot;web3swift&quot;<br>let mnemonics = &quot;fine have legal roof fury bread egg knee wrong idea must edit&quot; // Some mnemonic phrase<br>let keystore = try! BIP32Keystore(<br>    mnemonics: mnemonics,<br>    password: password,<br>    mnemonicsPassword: &quot;&quot;,<br>    language: .english)!<br>let name = &quot;New HD Wallet&quot;<br>let keyData = try! JSONEncoder().encode(keystore.keystoreParams)<br>let address = keystore.addresses!.first!.address<br>let wallet = Wallet(address: address, data: keyData, name: name, isHD: true)</pre><h3>Get Keystore Manager from wallet data</h3><pre>let data = wallet.data<br>let keystoreManager: KeystoreManager<br>if wallet.isHD {<br>    let keystore = BIP32Keystore(data)!<br>    keystoreManager = KeystoreManager([keystore])<br>} else {<br>    let keystore = EthereumKeystoreV3(data)!<br>    keystoreManager = KeystoreManager([keystore])<br>}</pre><h3>Get private key</h3><pre>let password = &quot;web3swift&quot;<br>let ethereumAddress = EthereumAddress(wallet.address)!<br>let pkData = try! keystoreManager.UNSAFE_getPrivateKeyData(password: password, account: ethereumAddress).toHexString()</pre><p>名詞解釋（簡易篇）</p><ul><li>HD Wallet（Hierarchical Deterministic Wallets）<br> 是一個系統可以從單一個 <strong>seed</strong> <strong>產生一樹狀結構儲存多組 keypairs（私鑰和公鑰）</strong>。好處是可以方便的備份、轉移到其他相容裝置（因為都只需要 seed），以及分層的權限控制等。</li><li>BIP ( Bitcoin Improvement Proposal )<br> BIP39 : 將 <strong>seed</strong> 用方便記憶和書寫的單字表示。一般由 <strong>12 個單字</strong>組成，稱為 <strong>mnemonic code(phrase)</strong>，中文稱為助記詞或助記碼。</li><li>Infura是一個可以讓你的DApp 快速接入以太坊的平台，不需要本地運行以太坊節點。以太坊許多知名的項目（MetaMask，Aragon，Gnosis，OpenZeppelin 等）都利用Infura 的API 將其應用程序連接到以太坊網絡。作為以太坊生態中最大的API 提供方。</li><li>ABI : <strong>應用二進位介面</strong>（application binary interface，縮寫為<strong>ABI</strong>）是指兩程式模組間的介面；通常其中一個程式模組會是函式庫或作業系統所提供的服務，而另一邊的模組則是使用者所執行的程式。</li><li>EIP2930 : Optional access lists<br> 因為有些合約有hardcode external call的gas 上限。對於這方面的問題，EIP2930提出一個<strong>新的交易類型</strong>，讓交易中多帶一個access list，即所有這筆交易即將讀寫的storage slot，並且先幫忙付掉第一次讀寫的gas，而真正交易讀寫該storage時，只會被要求付100 gas。</li><li>ENS : 以太坊名稱服務 (ENS) 是錢包地址、雜湊及其他機器可讀的識別碼的命名服務。</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b21daab391b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/web3swift-%E4%BD%BF%E7%94%A8%E7%AD%86%E8%A8%98-1-b21daab391b2">Web3Swift 使用筆記 1</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[SwiftUI — Animation動畫]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swiftui-animation%E5%8B%95%E7%95%AB-4005feae78e0?source=rss-a1e3cc66fc79------2</link>
            <guid isPermaLink="false">https://medium.com/p/4005feae78e0</guid>
            <dc:creator><![CDATA[ＬＵＬＵ]]></dc:creator>
            <pubDate>Wed, 08 Jun 2022 03:55:19 GMT</pubDate>
            <atom:updated>2022-06-08T09:19:18.279Z</atom:updated>
            <content:encoded><![CDATA[<h3>SwiftUI — Animation動畫</h3><p>自從接觸swiftUI動畫後覺得實在太好玩太有趣了！！今天想用簡單的例子跟大家分享😆</p><p>先建立需要手動點擊的畫面，定義了三個@State var 來建立狀態模型，初始值設為 false。圓與星形用ZStack來建立，將星形疊加在圓形上面。 使用onTapGesture偵測手勢。在 onTapGesture closure中，用 toggle() 來開啟狀態以改變View的外觀。</p><pre>struct ContentView: View {<br>    <br>    <a href="http://twitter.com/State">@State</a> private var circleColorChange = false<br>    <a href="http://twitter.com/State">@State</a> private var starColorChange = false<br>    <a href="http://twitter.com/State">@State</a> private var starSizeChange = false<br>    <br>    var body: some View {<br>        ZStack {<br>            Circle()<br>                .frame(width: 200, height: 200)<br>                .foregroundColor(circleColorChange ? Color(.systemBlue) : .black)<br>        <br>            Image(systemName: &quot;star.fill&quot;)<br>                .foregroundColor(starColorChange ? .yellow : .red)<br>                .scaleEffect(starSizeChange ? 7.0 : 5.0)<br>        }<br>        .onTapGesture {<br>                self.circleColorChange.toggle()<br>                self.starColorChange.toggle()<br>                self.starSizeChange.toggle()<br>        }<br>    }<br>}</pre><p>將程式以withAnimation包在onTapGesture中，呼叫withAnimation帶入參數為彈跳效果動畫。</p><pre>withAnimation(.spring(response: 0.2, dampingFraction: 0.2, blendDuration: 0.2)) {<br>                self.circleColorChange.toggle()<br>                self.starColorChange.toggle()<br>                self.starSizeChange.toggle()<br>            }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*fsErvAUoeg0etiR_hY_3-w.gif" /></figure><p>若想嘗試不同的動畫效果還有以下幾種參數</p><ol><li>easeOut : 速度一開始快，然後越來越慢。</li><li>easeIn : 速度一開始慢，然後越來越快。</li><li>easeInOut : 速度一開始慢，然後越來越快，最後再越來越慢（.default 的動畫效果跟 easeInOut 類似）。</li><li>linear : 維持固定的速度。</li><li>spring : 彈跳動畫效果。</li></ol><p>若想調整動畫時間可以在Animation中傳入參數duration。</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/swiftui-%E7%9A%84-animation-%E5%8B%95%E7%95%AB-2f8eb72d2756">SwiftUI 有趣的 animation 動畫</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4005feae78e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swiftui-animation%E5%8B%95%E7%95%AB-4005feae78e0">SwiftUI — Animation動畫</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[SwiftUI- 警告 ‘animation’ was deprecated in iOS 15.0:]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swiftui-%E8%AD%A6%E5%91%8A-animation-was-deprecated-in-ios-15-0-49e239053107?source=rss-a1e3cc66fc79------2</link>
            <guid isPermaLink="false">https://medium.com/p/49e239053107</guid>
            <dc:creator><![CDATA[ＬＵＬＵ]]></dc:creator>
            <pubDate>Tue, 31 May 2022 07:11:07 GMT</pubDate>
            <atom:updated>2022-06-01T13:31:32.334Z</atom:updated>
            <content:encoded><![CDATA[<h3>SwiftUI- 警告 ‘animation’ was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead.</h3><p>製作動畫時不小心遇到的警告ＱＱ<br>直接上圖比較清楚 ⬇️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q0Pa-Z3l5h-BTHBI-Qx4-Q.png" /></figure><p>‘animation’ was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead. <br>意思是’animation’ 在 iOS 15.0 中已棄用：改用 withAnimation 或 animation(_:value:)。</p><p>一開始找到的文章都是說我需要告訴Xcode要怎麼處理動畫的部分，因此需要給他一個Equatable protocol or State or Binding 或任何其他允許更新它的value。</p><p>之後我嘗試用@Sate去判斷他的狀態像這樣</p><p><a href="https://stackoverflow.com/questions/69443588/how-to-replace-deprecated-animation-in-swiftui">How to replace deprecated .animation() in SwiftUI?</a></p><p>結果我的動畫就不動了ＱＱ</p><p>後來我找到這篇文章，讓view自己更新UUID，問題暫時被解決了。</p><p><a href="https://www.avanderlee.com/swiftui/disable-animations-transactions/">Disable animations on a specific view in SwiftUI using transactions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49e239053107" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swiftui-%E8%AD%A6%E5%91%8A-animation-was-deprecated-in-ios-15-0-49e239053107">SwiftUI- 警告 ‘animation’ was deprecated in iOS 15.0:</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[SwiftUI-關於@ViewBuilder & @escaping]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swiftui-%E9%97%9C%E6%96%BC-viewbuilder-f6221a954a63?source=rss-a1e3cc66fc79------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6221a954a63</guid>
            <dc:creator><![CDATA[ＬＵＬＵ]]></dc:creator>
            <pubDate>Tue, 24 May 2022 07:00:14 GMT</pubDate>
            <atom:updated>2022-05-24T07:03:04.798Z</atom:updated>
            <content:encoded><![CDATA[<p>在SwiftUI框架中使用很多的註解，雖然使語法非常簡潔，但是增加了初學者的理解難度ＱＱ</p><p>ViewBuilder是一個包含多個檢視的閉包。（直譯：A custom parameter attribute that constructs views from closures.）ＸＤ</p><p><a href="http://twitter.com/ViewBuilder">@ViewBuilder</a>可以在參數 closure 的 { } 裡生成多個元件</p><p>如何判斷function型別參數是否為ViewBuilder</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%88%A4%E6%96%B7-swiftui-%E7%9A%84-function-%E5%9E%8B%E5%88%A5%E5%8F%83%E6%95%B8%E6%98%AF-%E5%90%A6%E5%82%B5viewbuilder-9398c1346156">判斷 SwiftUI 的 function 型別參數是 否債ViewBuilder</a></p><h4>@escaping &amp; @ViewBuilder</h4><p>有@ViewBuilder時，當closure被標記為@escaping，這個值不會在初始化（init)時就被使用（@escaping特性，它允許我們存儲閉包，以便稍後使用）。<br>closure 屬於 reference types，他們實際存上存在於heap中</p><pre>struct GridStack&lt;Content: View&gt;: View {<br>    let rows: Int<br>    let columns: Int<br>    let content: (Int, Int) -&gt; Content<br><br>    var body: some View {<br>         VStack {<br>        ForEach(0 ..&lt; rows) { row in<br>            HStack {<br>                ForEach(0 ..&lt; self.columns) { column in<br>                    self.content(row, column)<br>                }<br>            }<br>         }<br>      }<br>   }<br>}</pre><p>第一行 struct GridStack&lt;Content: View&gt;: View，是 Swift 的泛型，它的意思是“你可以提供任意類型的內容，但必須遵守 View 協議。” 在冒號之後，又加了一個View，聲明 GridStack 本身也遵守View 協議。</p><p>特別注意一下 let content 這行它定義了一個closure必須接收兩個整數，並且返回某種我們可以顯示的內容。</p><p>現在我們有了一個自定義struct，我們可以用它寫一個view，像下面這樣：</p><pre>struct ContentView: View {<br>    var body: some View {<br>        GridStack(rows: 5, columns: 5) { row, col in<br>            Text(&quot;R\(row) C\(col)&quot;)<br>        }<br>    }<br>}</pre><p>GridStack可以接收各種型別，只要它們遵守View協議。因此，可以創建自己的stack 。</p><pre>GridStack(rows: 5, columns: 5) { row, col in<br>    HStack {<br>        Image(systemName: &quot;\(row * 5+ col).circle&quot;)<br>        Text(&quot;R\(row) C\(col)&quot;)<br>    }<br>}</pre><p>我們還可以用SwiftUI 的一個特性，叫view builder，它允許我們傳入多個view，讓view builder 為我們創建stack 。</p><p>為了使用@view builder ，需要給GridStack 初始化，因此用SwiftUI 的＠view builder 系統來標記 content closure</p><pre>init(rows: Int, columns: Int, @ViewBuilder content: @escaping (Int, Int) -&gt; Content) {<br>    self.rows = rows<br>    self.columns = columns<br>    self.content = content<br>}</pre><p>有@ViewBuilder時，當closure被標記為@escaping，這個值不會在初始化（init)時就被使用（@escaping特性，它允許我們存儲閉包，以便稍後使用）。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6221a954a63" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swiftui-%E9%97%9C%E6%96%BC-viewbuilder-f6221a954a63">SwiftUI-關於@ViewBuilder &amp; @escaping</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[SwiftUI-什麼是@Published? ObservableObject?]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swiftui-%E4%BB%80%E9%BA%BC%E6%98%AF-published-observableobject-eb950f8295a?source=rss-a1e3cc66fc79------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb950f8295a</guid>
            <dc:creator><![CDATA[ＬＵＬＵ]]></dc:creator>
            <pubDate>Tue, 17 May 2022 07:09:46 GMT</pubDate>
            <atom:updated>2022-05-18T02:11:53.559Z</atom:updated>
            <content:encoded><![CDATA[<p>最近文章會更新的勤勞一些（應該ＸＤ</p><p><a href="http://twitter.com/Published">@Published</a> 是 SwiftUI 中非常好用的wrapper，它允許我們創建”可觀察的” object，當這些object發生更改時會自動宣布通知。 SwiftUI 將自動監控此類更改，並重新調用data的任何view的 body 屬性。</p><p>無論何時更改帶有標記為 <a href="http://twitter.com/Published">@Published</a> 的屬性的object，都會reload使用該object的所有view以反應這些更改。</p><p>example:</p><pre>class A: ObservableObject {<br>     var items = [Int]()<br>}</pre><p>這符合ObservableObject protocol, SwiftUI 的view可以觀察它的變化。但是因為沒有用@Published 標記，所以永遠不會發送任何更改通知。</p><p>若想要從items 中添加或刪除某些內容時發送更改公告，可以使用@Published 對其進行標記。</p><pre><strong>class</strong> A: ObservableObject {<br>    @Published <strong>var</strong> items = [Int]()<br>}</pre><p>因此不需要做任何事情<a href="http://twitter.com/Published">@Published</a> 將 willSet 觀察者添加到items，以便任何更改都會自動發送給觀察者。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb950f8295a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swiftui-%E4%BB%80%E9%BA%BC%E6%98%AF-published-observableobject-eb950f8295a">SwiftUI-什麼是@Published? ObservableObject?</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[SwiftUI-如何及何時使用Equatable and Identifiable protocols]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swiftui-%E5%A6%82%E4%BD%95%E5%8F%8A%E4%BD%95%E6%99%82%E4%BD%BF%E7%94%A8equatable-and-identifiable-protocols-dc1cd6598ae0?source=rss-a1e3cc66fc79------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc1cd6598ae0</guid>
            <dc:creator><![CDATA[ＬＵＬＵ]]></dc:creator>
            <pubDate>Mon, 16 May 2022 08:05:36 GMT</pubDate>
            <atom:updated>2022-05-16T12:19:42.891Z</atom:updated>
            <content:encoded><![CDATA[<p>內個..如果有中英參雜的部分請多包涵&gt;&lt;我實在不確定如何用我的口語來翻譯比較正確, 所以還是請大家直接看英文</p><ol><li>Equatable protocols 可以比較相同類型的instances, 可以使用“==”比較是否相等, 也可以使用 “!=”比較value的不相等</li></ol><p><a href="https://developer.apple.com/documentation/swift/equatable">Equatable | Apple Developer Documentation</a></p><p>2. Identifiable protocols 適用於任何“需要穩定自我的身份”<br>（原文：The Identifiable protocol is for use with any type that needs to have a stable notion of identity.）<br>唯一的要求是需要 ”id”, 讓他自己決定 id 是什麼型別, 同時須符合 Hashbale 的協議</p><p><a href="https://developer.apple.com/documentation/swift/identifiable">Identifiable | Apple Developer Documentation</a></p><p>以下範例是我在做翻牌遊戲一部分的 code 之後會再放上完整的</p><pre>struct Card: Identifiable {<br>        var isFaceUp: Bool = false<br>        var isMatched: Bool = false<br>        var content: CardContent<br>        var id: Int<br>    }</pre><p>以struct 定義 Card 的 model, 並讓每一張卡都有獨特的id, 因此使用 Identifiable protocol<br>後面因為需要由程式判斷兩張卡的內容是否為相同的,所以使用Equatable procotol</p><pre>struct MemoryGame&lt;CardContent&gt; where CardContent: Equatable {<br>    private(set) var cards: Array&lt;Card&gt;<br>    <br>    private var indexOfTheOneAndOnlyFaceUpCard: Int?<br>    <br>    mutating func choose(_ card: Card) {<br>        if let chosenIndex = cards.firstIndex(where: {$0.id == card.id}),<br>           !cards[chosenIndex].isFaceUp,<br>           !cards[chosenIndex].isMatched {<br>            <br>            if let potentailMatchIndex = indexOfTheOneAndOnlyFaceUpCard {<br>                if cards[chosenIndex].content == cards[potentailMatchIndex].content {<br>                    cards[chosenIndex].isMatched = true<br>                    cards[potentailMatchIndex].isMatched = true<br>                }<br>                indexOfTheOneAndOnlyFaceUpCard = nil<br>            } else {<br>                for index in cards.indices {<br>                    cards[index].isFaceUp = false<br>                }<br>                indexOfTheOneAndOnlyFaceUpCard = chosenIndex<br>            }<br>            cards[chosenIndex].isFaceUp.toggle()<br>        }<br>    }<br>}</pre><p>參考文章：</p><ul><li><a href="https://khawerkhaliq.com/blog/swift-equatable-identifiable/#The_Identifiable_protocol">When and how to use the Equatable and Identifiable protocols in Swift</a></li><li><a href="https://www.hackingwithswift.com/books/ios-swiftui/working-with-identifiable-items-in-swiftui">Working with Identifiable items in SwiftUI</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc1cd6598ae0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swiftui-%E5%A6%82%E4%BD%95%E5%8F%8A%E4%BD%95%E6%99%82%E4%BD%BF%E7%94%A8equatable-and-identifiable-protocols-dc1cd6598ae0">SwiftUI-如何及何時使用Equatable and Identifiable protocols</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[SwiftUI — 什麼是@State？]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swiftui-%E4%BB%80%E9%BA%BC%E6%98%AF-state-e4e5ee90e28?source=rss-a1e3cc66fc79------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4e5ee90e28</guid>
            <dc:creator><![CDATA[ＬＵＬＵ]]></dc:creator>
            <pubDate>Fri, 13 May 2022 07:46:44 GMT</pubDate>
            <atom:updated>2022-05-17T07:25:49.385Z</atom:updated>
            <content:encoded><![CDATA[<h3>SwiftUI 什麼是@State？</h3><p>內個..由於前陣子刷題有點刷膩了😝<br>所以開始研究一下SwiftUI(⁎⁍̴̛ᴗ⁍̴̛⁎)</p><p>哎呀我的天一開始看這官方文件真的超級矇ＱＱ<br>簡單來說，SwiftUI 用狀態決定如何顯示和更新畫面。</p><p>由於一開始在初始化(init)標記為 ＠State 時，<strong><em>並沒有實際創建出一個變數</em></strong>，而是提示 SwiftUI 在後台創建“某物”來存儲設置的內容並從現在開始對其進行監控。<br>因此@State var 僅充當訪問此wrapper的delegate<br>每次寫入 @State 變數時，SwiftUI 都會知道它正在監視它。 它還將知道 @State 變數是否是從View中讀取的。 能夠在更改此變數後重新計算在其主體中引用了 @State 變數的View。</p><p>example:</p><pre>struct CardView: View {<br>    <br>    var isFaceUp: Bool = true<br>    <br>    var body: some View {<br>        ZStack {<br>            let shape = RoundedRectangle(cornerRadius: 20.0)<br>            if card.isFaceUp {<br>                shape.fill().foregroundColor(.white)<br>                shape.strokeBorder(lineWidth: 3)<br>                Text(&quot;🚀&quot;).font(.largeTitle)<br>            } else {<br>                shape.fill()<br>            }<br>        }.OnTapGesture {<br>             isFaceUp = !isFaceUp<br>       }<br>    }<br>}</pre><p><em>❌此時 isFaceUp = !isFaceUp的地方會出現Cannot assign to property: ‘self’ is immutable的錯誤<br>因為在執行 if isFaceUp的時候變數還沒有被創建</em></p><p>此時只要在 var isFaceUp: Bool = true 的前面加上@State ，紅色的錯誤就會消失了</p><p>參考文章：</p><ul><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/%E7%94%A8%E7%8B%80%E6%85%8B%E8%A8%AD%E8%A8%88-swiftui-%E7%95%AB%E9%9D%A2-%E8%AA%8D%E8%AD%98-state-property-binding-27fea6885ead">用狀態設計 SwiftUI 畫面 — 認識 State property</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/swiftui-state-%E7%9A%84%E9%80%B2%E9%9A%8E%E8%A7%A3%E6%9E%90-6e98cb1dc87a">SwiftUI @State 的進階解析</a></li></ul><p><a href="https://developer.apple.com/documentation/swiftui/state">https://developer.apple.com/documentation/swiftui/state</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4e5ee90e28" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swiftui-%E4%BB%80%E9%BA%BC%E6%98%AF-state-e4e5ee90e28">SwiftUI — 什麼是@State？</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[Swift 每週五題 LeetCode(9)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-%E6%AF%8F%E9%80%B1%E4%BA%94%E9%A1%8C-leetcode-9-b71b8b2a8802?source=rss-a1e3cc66fc79------2</link>
            <guid isPermaLink="false">https://medium.com/p/b71b8b2a8802</guid>
            <dc:creator><![CDATA[ＬＵＬＵ]]></dc:creator>
            <pubDate>Tue, 29 Mar 2022 07:08:34 GMT</pubDate>
            <atom:updated>2022-03-29T11:00:23.015Z</atom:updated>
            <content:encoded><![CDATA[<p>嗨嗨～各位～最近深深有感體力追不上年紀ＱＱ即使每週運動2–3天,在經過兩天假日10小時的課程,還是得在週一休假放過自己&gt;&lt;</p><p>正題開始～～</p><h4>69. Sqrt(x) (Easy)</h4><p>這是一題開根號的題目～<br>因為只需要return 整數所以我用了最～～簡單的方法ＸＤ</p><p><a href="https://leetcode.com/problems/sqrtx/">Sqrt(x) - LeetCode</a></p><pre>func mySqrt(_ x: Int) -&gt; Int {<br>    //    return Int(sqrt(Double(x))) 也可以直接call function<br>    var result = 0<br>    var i = 1<br>    while i*i &lt;= x {<br>        result = i<br>        i += 1<br>    }<br>    return result<br>}</pre><h4>70. Climbing Stairs (Easy)</h4><p>每一次可以走一步或是兩步,計算最後有幾種方式可以到達終點<br><a href="https://leetcode.com/problems/climbing-stairs/">https://leetcode.com/problems/climbing-stairs/</a></p><pre>func climbStairs(_ n: Int) -&gt; Int {<br>    var step = [0, 1 , 1]<br>    for i in 1...n + 1 {<br>        if i &lt;= 2 {<br>            continue<br>        }<br>        step.append(step[i - 1] + step[i - 2])<br>    }<br>    return step.last!<br>}</pre><h4>73. Set Matrix Zeroes (Medium)</h4><p>這裡需要把”原本”數字是0的位置的上下左右都改成0</p><p><strong>Example :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/0*k9qvT_G4WHjKSAPW.jpg" /></figure><pre><strong>Input:</strong> matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]<br><strong>Output:</strong> [[0,0,0,0],[0,4,5,0],[0,3,1,0]]</pre><p>原本是0的位置只有[0, 0] [3, 0]的位置,所以從此位置望上,下,左,右的位置的數字都改成0,[0,1,2,0] →[0,0,0,0]</p><pre>func setZeroes(_ matrix: inout [[Int]]) {<br>    let m = matrix.count <br>    let n = matrix[0].count<br>    var rows = [Int]() <br>    var cols = [Int]()<br>    <br>    for i in 0..&lt;m {<br>        for k in 0..&lt;n{<br>            if matrix[i][k] == 0 {<br>                rows.append(i)<br>                cols.append(k)<br>            }<br>        }<br>    }<br>    <br>    for col in cols {<br>        for i in 0..&lt;m {<br>            matrix[i][col] = 0<br>        }<br>    }<br>    for row in rows {<br>        for k in 0..&lt;n {<br>            matrix[row][k] = 0<br>        }<br>    }<br>}</pre><h4>75. Sort Colors (Medium)</h4><p>這題最大的重點就是不能直接用sort function,直接上解答</p><p><a href="https://leetcode.com/problems/sort-colors/">Sort Colors - LeetCode</a></p><pre>func sortColors(_ nums: inout [Int]) {<br>    var min = 0<br>    var max = nums.count - 1<br>    var i = 0<br>    <br>    while i &lt;= max {<br>        if nums[i] == 0 {<br>            nums.swapAt(i, min)<br>            min += 1<br>            i += 1<br>        } else if nums[i] == 1 {<br>            i += 1<br>        } else if i &lt;= max &amp;&amp; nums[i] == 2 {<br>            nums.swapAt(i, max)<br>            max -= 1<br>        }<br>    }<br>}<br>var color = [0, 1, 0]</pre><h4>76. Minimum Window Substring (Hard)</h4><p>這題真的好難ＱＱ直接看答案然後想辦法裡解</p><p><a href="https://leetcode.com/problems/minimum-window-substring/">Minimum Window Substring - LeetCode</a></p><pre>func minWindow(_ s: String, _ t: String) -&gt; String {<br>    <br>    guard s.count &gt;= t.count else {<br>        return &quot;&quot;<br>    }<br>    <br>    let sStr = Array(s)<br>    let tStr = Array(t)<br>    <br>    var tCurr = [Character:Int]()<br>    for i in 0..&lt;tStr.count {<br>        let letter = tStr[i]<br>        tCurr[letter, default: 0] += 1<br>    }<br>    <br>    var charsInWindow = 0<br>    var minStr = &quot;&quot;<br>    var minLen = Int.max<br>    var start = 0<br>    for end in 0..&lt;sStr.count {<br>        let letter = sStr[end]<br>        if tCurr[letter] != nil {<br>            if tCurr[letter]! &gt; 0 {<br>                charsInWindow += 1<br>            }<br>            tCurr[letter]! -= 1<br>        }<br>        while start&lt;sStr.count &amp;&amp;<br>                (tCurr[sStr[start]] == nil ||<br>                 (tCurr[sStr[start]] != nil &amp;&amp; tCurr[sStr[start]]! &lt; 0)) {<br>            if tCurr[sStr[start]] != nil {<br>                tCurr[sStr[start]]! += 1<br>            }<br>            start += 1<br>        }<br>       <br>        if charsInWindow == tStr.count {<br>            if end-start+1 &lt; minLen {<br>                minLen = end-start+1<br>                minStr = String(sStr[start...end])<br>            }<br>        }<br>    }<br>    return minStr<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b71b8b2a8802" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-%E6%AF%8F%E9%80%B1%E4%BA%94%E9%A1%8C-leetcode-9-b71b8b2a8802">Swift 每週五題 LeetCode(9)</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[Swift 每週五題 LeetCode(8)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-%E6%AF%8F%E9%80%B1%E4%BA%94%E9%A1%8C-leetcode-8-a86d23cb428f?source=rss-a1e3cc66fc79------2</link>
            <guid isPermaLink="false">https://medium.com/p/a86d23cb428f</guid>
            <dc:creator><![CDATA[ＬＵＬＵ]]></dc:creator>
            <pubDate>Sun, 20 Mar 2022 03:29:43 GMT</pubDate>
            <atom:updated>2022-03-20T12:34:23.375Z</atom:updated>
            <content:encoded><![CDATA[<p>嗨嗨～我是這週五發覺到自己是帝寶的孩子（上帝的寶貝簡稱）ＸＤ哈哈有聽偷聽史多利的朋友應該會知道😎由於這個週末要到公司加班(ing)所以週五先休了一天假,剛好那天早上我家附近的工業區發生火災大塞車＠＠讓我逃過遲到保住出勤獎金：Ｄ</p><p>正題開始！</p><h3>54. Spiral Matrix(Medium)</h3><p>老實說這題我逃避了一天：Ｐ在想到底怎麼處裡好,最後還是決定給方向直接指示行動位置</p><p><a href="https://leetcode.com/problems/spiral-matrix/">Spiral Matrix - LeetCode</a></p><pre>func spiralOrder(_ matrix: [[Int]]) -&gt; [Int] {<br>    <br>    var result = [Int]()<br>    var top = 0<br>    var left = 0<br>    var bottom = matrix.count - 1<br>    var right = matrix[0].count - 1<br>    var direction = 0<br>    <br>    while top &lt;= bottom &amp;&amp; left &lt;= right {<br>        if direction % 4 == 0 {<br>            for i in left...right {<br>                result.append(matrix[top][i])<br>            }<br>            top += 1<br>        }<br>        if direction % 4 == 1 {<br>            for i in top...bottom {<br>                result.append(matrix[i][right])<br>            }<br>            right -= 1<br>        }<br>        if direction % 4 == 2 {<br>            for i in stride(from: right, through: left, by: -1) {<br>                result.append(matrix[bottom][i])<br>            }<br>            bottom -= 1<br>        }<br>        if direction % 4 == 3 {<br>            for i in stride(from: bottom, through: top, by: -1) {<br>                result.append(matrix[i][left])<br>            }<br>            left += 1<br>        }<br>        direction += 1<br>    }<br>    <br>    return result<br>}</pre><h4>55. Jump Game(Medium)</h4><p>這題也花了一點時間理解題目,最初位於陣列的第一個index，數組中的每個元素都代表在該位置的最大跳躍長度,如果可以到達最後一個返回 true，否則返回 false。<br><a href="https://leetcode.com/problems/jump-game/">https://leetcode.com/problems/jump-game/</a></p><pre>func canJump(_ nums: [Int]) -&gt; Bool {<br>    var jump = 0<br>    var i = 0<br>    <br>    while i &lt;= jump {<br>        jump = max(jump, i + nums[i])<br>        i += 1<br>        if jump &gt;= nums.count - 1 {<br>            return true<br>        }<br>    }<br>    return false<br>}</pre><h4>56. Merge Intervals(Medium)</h4><p>題目中[[1, 3][2, 6]],從1到6中間會有2, 3, 4, 5合併所有重疊區間，並返回一個包含輸入中所有區間的”非重疊”區間數組,所以最後輸出會是[1, 6]。</p><p><a href="https://leetcode.com/problems/merge-intervals/">Merge Intervals - LeetCode</a></p><pre>func merge(_ intervals: [[Int]]) -&gt; [[Int]] {<br>    var result: [[Int]] = []<br>    var arr = intervals.sorted { left, right in<br>        left[0] &lt; right[0]<br>    }<br>    var now = arr[0] //當下的位置<br>    for i in 1..&lt;arr.count { //從[0]開始所以回圈從第一個位置開始檢查<br>        if now[1] &gt;= arr[i][0] { //若陣列中[1]比前者大<br>            now = [now[0],max(now[1], arr[i][1])] //now=當下或是較大的<br>        } else {<br>            result.append(now)<br>            now = arr[i]<br>        }<br>    }<br>    result.append(now)<br>    return result<br>}</pre><h4>62. Unique Paths(Medium)</h4><p>這幾題都是這種棋盤類型的題目ＱＱ<br><a href="https://www.youtube.com/watch?v=zQ6lx5tZ1Xw">https://www.youtube.com/watch?v=zQ6lx5tZ1Xw</a></p><p>請直接看影片解說比較清楚,再附上Swift解法<br><a href="https://leetcode.com/problems/unique-paths/">https://leetcode.com/problems/unique-paths/</a></p><pre>func uniquePaths(_ m: Int, _ n: Int) -&gt; Int {<br>    var result = Array(repeating: 1, count: n)<br>    for i in 1..&lt;m {<br>        for k in 1..&lt;n {<br>            result[k] = result[k] + result[k-1]<br>        }<br>    }<br>    return result[n-1]<br>}</pre><h4>66. Plus One(Easy)</h4><p>簡單來說就是將整數加一併返回結果數字陣列。<br><a href="https://leetcode.com/problems/plus-one/">https://leetcode.com/problems/plus-one/</a></p><pre>func plusOne(_ digits: [Int]) -&gt; [Int] {<br>    var carry: Int = 1<br>    var result = digits<br>    <br>    for i in stride(from: digits.count - 1, to: -1, by: -1) {<br>        let value = (digits[i] + carry) % 10<br>        carry = (digits[i] + carry) / 10<br>        result[i] = value<br>    }<br>    if carry == 1 {<br>        result.insert(1, at: 0)<br>    }<br>    return result<br>}</pre><p>補充stride用法：<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/swift-3%E7%9A%84for%E8%BF%B4%E5%9C%88%E4%B8%8D%E5%8F%AA%E6%9C%83%E6%AF%8F%E6%AC%A1%E5%8A%A01-5d4d6e14197">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/swift-3%E7%9A%84for%E8%BF%B4%E5%9C%88%E4%B8%8D%E5%8F%AA%E6%9C%83%E6%AF%8F%E6%AC%A1%E5%8A%A01-5d4d6e14197</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a86d23cb428f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-%E6%AF%8F%E9%80%B1%E4%BA%94%E9%A1%8C-leetcode-8-a86d23cb428f">Swift 每週五題 LeetCode(8)</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[Swift 每週五題 LeetCode(7)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-%E6%AF%8F%E9%80%B1%E4%BA%94%E9%A1%8C-leetcode-7-4e446fede3f0?source=rss-a1e3cc66fc79------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e446fede3f0</guid>
            <dc:creator><![CDATA[ＬＵＬＵ]]></dc:creator>
            <pubDate>Mon, 14 Mar 2022 03:05:01 GMT</pubDate>
            <atom:updated>2022-03-15T05:04:57.069Z</atom:updated>
            <content:encoded><![CDATA[<p>今天是白色情人節！也是愛因斯坦的生日ＸＤ他說：『邏輯可以帶你從Ａ到Ｂ,而想像力可以帶你去任何地方😆』沒有計劃也沒關係～靠著想象怎麼浪漫都可以～祝大家白色情人節快樂☺️</p><h4>46. Permutations (Medium)</h4><p>題目會給一組陣列,要列出陣列內數字的排列組合<br><strong>Example 1:</strong></p><pre><strong>Input:</strong> nums = [1,2,3]<br><strong>Output:</strong> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]</pre><p><a href="https://leetcode.com/problems/permutations/">Permutations - LeetCode</a></p><pre>func permute(_ nums: [Int]) -&gt; [[Int]] {<br>    var result : [[Int]] = []<br>    var numeros = nums<br>    <br>    // Base case<br>    if (nums.count == 1){<br>        return [nums]<br>    }<br>    <br>    var perms : [[Int]] = []<br>    <br>    for _ in 0..&lt;nums.count {<br>        let firstElement = numeros.first!<br>        numeros.removeFirst()<br>        // [2, 3] -&gt; perms remove 2 -&gt; 3<br>        perms = permute(numeros) // 遞迴 [[3]] // [[2]] //<br>        <br>        for i in 0..&lt;perms.count {<br>            perms[i].append(firstElement) // [[3,2]]  // [[2,3]]<br>        }<br>        <br>        numeros.append(firstElement) // [3, 2]<br>        <br>        // Add permutiations to result array<br>        for i in 0..&lt;perms.count {<br>            result.append(perms[i])<br>        }<br>        <br>    }<br>    <br>    return result<br>}</pre><h4>48. Rotate Image (Medium)</h4><p><a href="https://leetcode.com/problems/rotate-image/">https://leetcode.com/problems/rotate-image/</a><br><strong>Example 1:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/0*PkyceozIQBIL4vLF.jpg" /></figure><pre><strong>Input:</strong> matrix = [[1,2,3],[4,5,6],[7,8,9]]<br><strong>Output:</strong> [[7,4,1],[8,5,2],[9,6,3]]</pre><p>請把圖向右轉90度：Ｐ（把每組陣列中第一個數拿出來）</p><pre>func rotate(_ matrix: inout [[Int]]) {<br>    var result: [[Int]] = []<br>    var tempArr: [Int] = [] //暫時儲存的[]<br>    let arrCount = matrix.count - 1<br>    <br>    for _ in 0...arrCount {<br>        for k in 0...arrCount { //先把第一個移除,再加回來<br>            let arr = matrix[arrCount - k].removeFirst()<br>            tempArr.append(arr)<br>        }<br>        result.append(tempArr) //最後加到二維陣列中<br>        tempArr = []<br>    }<br>    matrix = result<br>}</pre><h4>49. Group Anagrams (Medium)</h4><p>Given an array of strings strs, group <strong>the anagrams</strong> together. You can return the answer in <strong>any order</strong>.</p><p>An <strong>Anagram</strong> is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.</p><p><strong>Example 1:</strong></p><pre><strong>Input:</strong> strs = [&quot;eat&quot;,&quot;tea&quot;,&quot;tan&quot;,&quot;ate&quot;,&quot;nat&quot;,&quot;bat&quot;]<br><strong>Output:</strong> [[&quot;bat&quot;],[&quot;nat&quot;,&quot;tan&quot;],[&quot;ate&quot;,&quot;eat&quot;,&quot;tea&quot;]]</pre><p><a href="https://leetcode.com/problems/group-anagrams/">Group Anagrams - LeetCode</a></p><pre>func groupAnagrams(_ strs: [String]) -&gt; [[String]] {<br>    var result = [[String]]()<br>    var records = [String]()<br>    var flag = false //記錄狀態是否改變<br>    <br>    for str in strs {<br>        let recordItem = String(str.sorted())<br>        flag = false<br>        for i in 0..&lt;records.count {<br>            if records[i] == recordItem {<br>                result[i].append(str)<br>                flag = true<br>                break<br>            }<br>        }<br>        if flag == false {<br>            result.append([str])<br>            records.append(recordItem)<br>        }<br>    }<br>    return result<br>}</pre><h4>50. Pow(x, n) (Medium)</h4><p><a href="https://leetcode.com/problems/powx-n/">https://leetcode.com/problems/powx-n/</a><br>這題有個偷吃步的解法ＸＤ</p><pre>func myPow(_ x: Double, _ n: Int) -&gt; Double {<br>    return pow(x, Double(n)) // 第一個解法ＸＤ</pre><pre>    var n = n // 第二個解法<br>    var x = x<br>    if n == 0 {<br>        return 1<br>    }<br>    if n &lt; 0 {<br>        n = -n<br>        x = 1/x<br>    }<br>    var ans: Double = 1<br>    while n &gt; 0 {<br>        if n &amp; 1 != 0 {<br>            ans = ans * x<br>        }<br>        x = x * x<br>        n = n &gt;&gt; 1<br>    }<br>    return ans<br>}</pre><h4>53. Maximum Subarray (Easy)</h4><p><a href="https://leetcode.com/problems/maximum-subarray/">Maximum Subarray - LeetCode</a></p><p>找出總和最大的連續子數組</p><pre>func maxSubArray(_ nums: [Int]) -&gt; Int {<br>    let nums = nums<br>    var sum = nums[0]<br>    var current = nums[0]<br>    <br>    for i in 1..&lt;nums.count {<br>        current = max(current + nums[i], nums[i])<br>        sum = max(current, sum)<br>    }<br>    <br>    return sum<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e446fede3f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-%E6%AF%8F%E9%80%B1%E4%BA%94%E9%A1%8C-leetcode-7-4e446fede3f0">Swift 每週五題 LeetCode(7)</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>
    </channel>
</rss>