<?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 Woody Liu on Medium]]></title>
        <description><![CDATA[Stories by Woody Liu on Medium]]></description>
        <link>https://medium.com/@bestlifeforzhi?source=rss-9b825cda4fea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HmPtf5WWa4M6csebLsRiIg@2x.jpeg</url>
            <title>Stories by Woody Liu on Medium</title>
            <link>https://medium.com/@bestlifeforzhi?source=rss-9b825cda4fea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 06:59:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bestlifeforzhi/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[CombineProcessor]]></title>
            <link>https://bestlifeforzhi.medium.com/combineprocessor-df3c410a48bc?source=rss-9b825cda4fea------2</link>
            <guid isPermaLink="false">https://medium.com/p/df3c410a48bc</guid>
            <category><![CDATA[design-pattern-ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[combine]]></category>
            <dc:creator><![CDATA[Woody Liu]]></dc:creator>
            <pubDate>Tue, 04 Apr 2023 07:50:04 GMT</pubDate>
            <atom:updated>2023-04-04T07:50:04.455Z</atom:updated>
            <content:encoded><![CDATA[<h4>Combine, State machine, Testable</h4><p><a href="https://github.com/woodycatliu/CombineProcessor">GitHub - woodycatliu/CombineProcessor</a></p><p><em>As an avid user of the TCA architecture, I often find myself unable to use it in real-world work situations due to various factors, such as team goals, architecture, and versioning. However, for core and laborious functionalities that require state machines, I rely on CombineProcessor.</em></p><p>CombineProcessor is a lightweight state machine that takes inspiration from the TCA Reducer design. It removes UI layer APIs and introduces simple Combine extensions and meticulously designed interfaces for Unit Testing. This allows developers to concentrate on the interaction between states, while Processor handles testing.</p><p>Overall, CombineProcessor is a practical tool for state machine design that enables developers to focus on state interactions, with two simple ways of verifying state transitions&#39; correctness. This makes state machine design a lot easier and more convenient.</p><h3>Introduce</h3><p><a href="https://github.com/woodycatliu/CombineProcessor"><strong><em>CombineProcessor</em></strong></a> is a very useful and convenient tool that allows the design of state machines to focus more on the interactions between states. It also provides two ways to verify if the order of state transitions is correct.</p><ul><li>Console Output：<br>By filtering Processor ID: in the Xcode Console, you can see a complete printout of the handling time for each state and their interactions. This is very useful for debugging and understanding program execution.</li></ul><pre>// 036 為 Processor ID 末三碼<br>Processor ID: 036 - - Action - emailSignIn - date: 2023-04-04 05:48:17 +0000<br>Processor ID: 036 - - PrivateAction - signInEmail: dadwad, password: dadwad - date: 2023-04-04 05:48:17 +0000<br>Processor ID: 036 - - PrivateAction - fetchSomeToken dadwad - date: 2023-04-04 05:48:19 +0000<br>Processor ID: 036 - - PrivateAction - storeUser - date: 2023-04-04 05:48:20 +0000<br>Processor ID: 036 - - PrivateAction - updateStauts - date: 2023-04-04 05:48:20 +0000</pre><ul><li>Unit Test：<br>Users can use the test interface to verify the order of state transitions. These test interfaces can simulate different state transitions and verify if the processing of each state meets expectations. This way, users can be more confident in the correctness of the state machine.</li></ul><pre><br>await processor.test.composable.privateAction(sendAction: .appleSignIn, <br>                                              equal: PrivateAction.A)<br>        .nextPrivateAction(equal: PrivateAction.B)<br>        .nextPrivateAction(equal: PrivateAction.C)<br>        .nextPrivateAction(equal: PrivateAction.C)<br>        .nextPrivateAction(equal: PrivateAction.E)</pre><p>CombineProcessor provides a very convenient tool for the design of state machines, allowing users to focus more on the interactions between states. It also provides two ways to verify if the order of state transitions is correct.</p><h3>SignInProcessor</h3><p>Example for CombineProcessor</p><p><a href="https://github.com/woodycatliu/SignINProcessor">GitHub - woodycatliu/SignINProcessor</a></p><p>Suppose we have a login requirement where users can choose to log in with either an `<strong>email`</strong> or `<strong>Apple`</strong> account. After completing the login process, `<strong>Firebase Authorization`</strong> is used to verify the user and obtain their information, followed by obtaining an authentication token from our `<strong>own server`</strong> to complete the login flow.</p><h4>So we have three steps:</h4><ul><li>Email Sign In or Apple Sing In</li><li>Firebase Authorization</li><li>Own-Server Authorization</li></ul><h4>First</h4><p>Define Components</p><ul><li>Action: <br>An event that occurs in your application that can cause a state change.</li><li>PrivateAction: <br>An action that can only be dispatched internally by the processor.</li><li>State: <br>The current state of your application, stored as a struct.</li><li>Environment(Optional): <br>A container for all the methods that UseCases or state machines need to use.</li></ul><p>Please refer to the <a href="https://github.com/woodycatliu/SignINProcessor/blob/main/SignInProcessor/SignIn/ViewModel/SignInProcessor.swift">link</a> for complete information.</p><pre> enum Action {<br>        <br>        case appleSignIn<br>        <br>        case emailSignIn(_ email: String, _ password: String)<br>        <br>        case logout<br>        <br>        var privateAction: PrivateAction {<br>            switch self {<br>            case .appleSignIn: return .appleSignIn<br>            case .emailSignIn(let emil, let password): return .signInEmail(with: emil, password: password)<br>            case .logout: return .ready<br>            }<br>        }<br>    }<br><br> enum PrivateAction {<br>        <br>        case appleSignIn<br>        case signInEmail(with: String,<br>                         password: String)<br>        <br>        case signInProviderID(appleUser: AppleUser)<br><br>         ...<br>}<br><br>struct Environment { ... }<br><br>struct States: Equatable { ... }</pre><h4>Second</h4><p>Assemble State, Action, PrivateAction, and Environment using AnyProcessorReducer.</p><pre>var reducer: AnyProcessorReducer&lt;States, Action, PrivateAction, Environment&gt; {<br>        return AnyProcessorReducer(mutated: { action in<br>            return action.privateAction<br>        }, reduce: { states, privateAction, environment -&gt; ProcessorPublisher&lt;PrivateAction, Never&gt;? in<br>            <br>            switch privateAction {<br>                <br>            case .appleSignIn:<br>                states.stauts = .isSignIning<br>                return environment<br>                    .appleService.tryStart()<br>                    .catchToDeresultProcessor(onSuccess: PrivateAction.storeAppleUser,<br>                                              onError: PrivateAction.receiveError)<br>                <br>            case .signInEmail(with: let email, password: let password):<br>                states.stauts = .isSignIning<br>                return environment<br>                    .firebaseService<br>                    .signIn(with: email, password: password)<br>                    .catchToDeresultProcessor(onSuccess: { response in<br>                        return .fetchSomeToken(userFactory:<br>                                .init(firebaseResponse: response),<br>                                               email: response.email ?? &quot;Null&quot;,<br>                                               idToken: response.idToken)<br>                    }, onError: PrivateAction.receiveError)<br>       ...<br>}</pre><p><strong>Final</strong></p><p>Injection in Processor</p><pre><br>let processor = Processor(<br>                       initialState: States(stauts: .ready),<br>                        reducer: reducer,<br>                        environment: Environment()<br>                      )</pre><h4>Completed Test</h4><pre>await processor.test.composable.privateAction(sendAction: .appleSignIn, where: { action in<br>            guard let action else { return false }<br>            if case SignInProcessor.PrivateAction.appleSignIn = action {<br>                return true<br>            }<br>            return false<br>        })<br>        .nextPrivateAction(where: { action in<br>            guard let action else { return false }<br>            if case SignInProcessor.PrivateAction.storeAppleUser = action {<br>                return true<br>            }<br>            return false<br>        }).nextPrivateAction(where: {action in<br>            guard let action else { return false }<br>            if case SignInProcessor.PrivateAction.signInProviderID = action {<br>                return true<br>            }<br>            return false<br>        })</pre><h4>Congratulations</h4><p>You have completed the design of your login system and can now move on to designing other parts of your app, such as ViewModel and UI.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df3c410a48bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animate in RxSwift.]]></title>
            <link>https://bestlifeforzhi.medium.com/animate-in-rxswift-379ad9adb899?source=rss-9b825cda4fea------2</link>
            <guid isPermaLink="false">https://medium.com/p/379ad9adb899</guid>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[rxswift]]></category>
            <category><![CDATA[ui-animation]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Woody Liu]]></dc:creator>
            <pubDate>Fri, 04 Nov 2022 04:31:42 GMT</pubDate>
            <atom:updated>2022-11-04T04:31:42.713Z</atom:updated>
            <content:encoded><![CDATA[<h4>More declarative style programing with UIKit</h4><h4>Introduction</h4><p>Ouch, It’s a long time to update my notes for programming Swift in the medium.</p><p>Recently, I have focused on learning and getting more into RxSwift for my new job. Before this, I was Combine like but is no denying that there is lots of magic in RxSwift than Combine.</p><p>Last week, I have get an issue with how animate in RxSwift from my friend. In a storm brain, I try to extend this for animate into RxSwift.It’s simple and intuitive to build the animation, so please forgive me for omitting the explanation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe66b1bcbb7dbf76fa58bdb314e7ca39/href">https://medium.com/media/fe66b1bcbb7dbf76fa58bdb314e7ca39/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=379ad9adb899" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object-C Migrate to Swift]]></title>
            <link>https://bestlifeforzhi.medium.com/object-c-migrate-to-swift-e151312c459b?source=rss-9b825cda4fea------2</link>
            <guid isPermaLink="false">https://medium.com/p/e151312c459b</guid>
            <category><![CDATA[rxswift]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Woody Liu]]></dc:creator>
            <pubDate>Wed, 05 Oct 2022 05:49:30 GMT</pubDate>
            <atom:updated>2022-10-05T05:54:28.371Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>wranning</strong>：There is nothing, just a shitpost.</h4><h4><strong>At my new job, We are refactoring in full swing.</strong></h4><ul><li>Migrate to Swift</li><li>MVC to MVVM</li><li>Reactive programming (RxSwift)</li></ul><h4><strong>In a completed Application.</strong></h4><h3>My nonsense journal</h3><p>(It will be fun and not big deal) what I think, when I get the offer and the task for me. After two weeks, I has refactored one view controller and refactoring another one, (It&#39;s really fun, but hard), I must stress this.</p><h4>The Point to Solve</h4><ul><li>Lots of delegate pattern of multi components.<br>1. Refactor it<br>2. Build a middleware<br>3. Or just leave it alone.</li><li>Lots of reference containers those are not suitable migrated to reactive programming in full application<br>1. Refactor it<br>2. Build a middleware<br>3. Or just leave it alone.</li><li>3th AD SDK (We haven’t figured out a solution yet)<br>1. Just leave it alone.</li><li>bla bla bla bla…<br>1. Refactor it<br>2. Build a middleware<br>3. Or just leave it alone.</li></ul><p>There are many beautiful design of components in Object-c. As you see, those wheels we must to consider to refactor. But the more important are time required and scope of impact. And….the PM.</p><h4>What I Do</h4><pre>// Before: object-c <br>typedef void (^SomeCallback)(BOOL success, NSError *_Nullable error, NSArray *_Nullable whatever)) <br>    <br>- (void)getSomeList:(nonnull SomeToken *)token <br>                     callback:(nullable SomeCallback) callback;<br><br>// Swift <br>// first middleware<br>struct FirstMiddleware: ApiMiddleware {<br>    func getSomeList(token: SomeToken, completion: @escaping Result&lt;whatever, Error&gt; {...}<br>}<br><br>// Swift<br>// second middleware for reactive<br>struct SecondMiddleware: ObserableMiddleware {<br>    func getSomeList(token: SomeToken)-&gt; Obserable&lt;whaterer&gt; {...}<br>}</pre><h4>Delegate</h4><pre>// Before: object-c<br>@protocol WhateverDelegate &lt;NSObject&gt;<br>- (void) foo:(SomeToken * _Nullable)token refreshToken:(NSString *_Nullable)refreshToken error:(NSError *_Nullable)error;<br>@end<br><br>@interface WhateverObject () &lt;WhateverDelegate&gt;<br><br>// create delegate middleware<br>class WhateverDelegateProxy: NSObject, ObservableType, WhateverDelegate {<br>typealias E = Event<br>private let publish: PublishRelay&lt;FooResult&gt; = .init()<br><br>func subscribe&lt;O&gt;(_ observer: O) -&gt; Disposable where O: ObserverType, E == O.E {<br>        subject.bind(to: observer)<br>  }<br><br>func foo(_ token: SomeToken?, refreshToken: String?, error: Error?) { <br>    publish.accept(FooResult(...))}<br>  }<br><br><br>// migrate swift<br>class WhateverObjectSwift {<br>   func bind() {<br>       let proxy = WhateverDelegateProxy()<br>       model.delegate = proxy<br>      proxy.bind(to:...).disposed(by: bag)<br>   }<br>}</pre><p><a href="https://hackmd.io/@WoodyLiu/SkWXJP5zj">My hackmd</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e151312c459b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux_MVVM_2 #Swift]]></title>
            <link>https://bestlifeforzhi.medium.com/redux-mvvm-2-swift-cd3ee3279f69?source=rss-9b825cda4fea------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd3ee3279f69</guid>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Woody Liu]]></dc:creator>
            <pubDate>Thu, 25 Aug 2022 09:46:25 GMT</pubDate>
            <atom:updated>2022-08-25T09:46:25.870Z</atom:updated>
            <content:encoded><![CDATA[<p>MVVM &amp; Redux_Page.2</p><p><a href="https://bestlifeforzhi.medium.com/redux-mvvm-swift-7b4655700b54/">previous</a></p><p>前言 <br><br> 還記得上一章介紹 Reducer&lt;State, Action&gt; 缺點時提到。</p><ul><li>沒有 <strong>Model</strong> 層的接口，不利於 Reuse 與 測試。</li><li>Action 無法串接成 Action Chain，無法循環利用。</li></ul><p>這一章節將會引入 Environment 與 Action 循環兩個功能。</p><p>Code Review</p><pre>Utility<br>    └── ViewModelComponents<br>            ├── BasicActionExcutorViewModel.swift<br>            ├── CellViewModelConfigureHandler.swift<br>            ├── ExcuteAction.swift<br>            └── TableViewModelProtocol.swift</pre><p>Environment</p><pre>typealias Reducer&lt;State, Action, EnvironmentModel&gt; = (inout State, Action, inout EnvironmentModel)-&gt;()</pre><p><em>Reducer&lt;State, Action, Environment&gt;</em></p><ul><li>Environment: Reducer 的第三個參數，提供 <strong>Method</strong> 與 外部參數的接口。</li><li>使用策略模式，在執行 reducer 時注入其中，可達到商業邏輯可 <strong>Reuse</strong> 也可建立 <strong>Fake</strong> 方便編寫測試。</li></ul><p><em>Action 循環</em></p><pre>typealias Reducer&lt;State, Action, EnvironmentModel&gt; = (inout State, Action, inout EnvironmentModel)-&gt;(Action)?<br><br>class BasicActionExcutorViewModel&lt;State, Action, EnvironmentModel&gt;: ActionExcutor {<br>    func excute(_ action: Action) {<br>        if let action = reducer(&amp;state, action, &amp;environment) {<br>            excute(action)<br>        }<br>    }<br>}<br><br>// 正確 example:<br><br>let reducer = Reducer { state, action, envi in<br><br>   switch action {<br>       case a:<br>       // do something <br>       return Action.c <br>       case b: <br>       // do something.  <br>       return Action.c<br>       case c:<br>       // do something<br>       return nil<br>   }<br>}<br><br>// 錯誤example :<br><br>let reducer = Reducer { state, action, envi in<br><br>   switch action {<br>       case a:<br>       // do something <br>       return Action.b <br>       case b: <br>       // do something.  <br>       return Action.a<br>       case c:<br>       // do something<br>       return nil<br>   }<br>}</pre><p>注意：Action.a and Action.b 造成無限循環，在設計時要小心。</p><blockquote>Reducer return 下一步動作的 action，再利用 Recursion 機制做遞迴呼叫。 如 BasicActionExcutorViewModel func excute(_ action:) 達到 action 可組裝 與 重復使用。</blockquote><p><strong>優點</strong></p><ul><li>Environment 利於測試與reuse</li><li>action 串接讓邏輯可以串接，讓程式碼更易於符合單一原則。(註1)</li></ul><p><strong>缺點</strong></p><ul><li>action 無法在異步任務中達成串接功能。</li><li>environment 的封裝異步任務，對於任務管理的需求增加設計難度。</li></ul><blockquote>註一：Action 可串接的設計，利於編寫代碼時更易於習慣拆分邏輯，讓method更趨向 unint 的特性</blockquote><p>後言：</p><p>接下來就不會再優化Reducer 的功能，因為要處理異步的需求的話，以當前的iOS版本，自己編寫輪子工程太大，建議使用功能完整且高度優化的三方庫來達成，比如 <a href="https://github.com/SwiftRex/SwiftRex">SwiftRex</a>, <a href="https://github.com/pointfreeco/swift-composable-architecture">TCA</a> 。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd3ee3279f69" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux_MVVM #Swift]]></title>
            <link>https://bestlifeforzhi.medium.com/redux-mvvm-swift-7b4655700b54?source=rss-9b825cda4fea------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b4655700b54</guid>
            <dc:creator><![CDATA[Woody Liu]]></dc:creator>
            <pubDate>Thu, 25 Aug 2022 09:44:04 GMT</pubDate>
            <atom:updated>2022-08-25T09:47:37.632Z</atom:updated>
            <content:encoded><![CDATA[<p>MVVM &amp; Redux _ Page 1.</p><p>在開始 Review 程式碼 之前，先來討論一下架構，也就是今天的主題。<br> 在了解架構時不得就不先提一下 <strong>設計模式</strong></p><p><strong>設計模式</strong><br> 一種解決不同情況的方案<br> 在物件導向中就是不同物件之間的相互關係的設計</p><p><strong>所以不同的設計模式有可能物件之間的相互關係設計是相同的，差別在於所解決的問題。(註一)</strong></p><p><strong>架構</strong><br> 為了解決所有情況的問題產生的一種方案。<br> 為了解決 <strong>所有情況</strong> , 由複數的設計模式組合成的。</p><ul><li>一個DB系統的架構</li><li>前端的 MVC、MVP、MVVM</li><li>AVPlayer、UITableView 都有應用不同的架構</li></ul><pre>flowchart LR<br><br>DeP(Design Pattern)<br>Solution--&gt;DeP</pre><pre>flowchart RL<br><br>Goal((Core Goal))<br>Sub{SubGoals}<br>A([Architecture])<br>B(Design Pattern)<br>C(Design Pattern)<br>D(Design Pattern)<br>E(Design Pattern)<br><br>Sub-.-&gt;Goal<br>A--&gt;Sub<br>B--&gt;A<br>C--&gt;A<br>D--&gt;A<br>E--&gt;A</pre><p><em>每一種架構都有它要解決的問題/目標</em></p><p>註一： Manager 跟 Adapter 非常的相近。</p><p><strong>How</strong><br> 再決定架構前，釐清 &gt; 規劃</p><p><strong>釐清</strong></p><ul><li>專案需求</li><li>架構目標</li></ul><p><strong>規劃</strong></p><ul><li>編程風格</li><li>定義分層</li><li>選擇依賴庫</li></ul><p><strong>Clean Architecture (乾淨的架構)</strong><br> <em>終極目標</em></p><p><strong>解決的問題</strong></p><ul><li>商業邏輯與依賴庫的耦合</li><li>DB</li><li>UI</li><li>硬體</li><li>其他 Framework</li><li>程式碼的肥大</li><li>不易於擴充與維護</li></ul><p><strong>今天程式碼的架構選擇</strong></p><pre>你可以先了解：<br>  - 單向數據流 (Ony-Way Data Flow)<br>  - 響應式編程 (Reactive Proframming)</pre><p><em>Redux &amp; MVVM</em></p><blockquote>Redux 的原則<br> MVVM 的架構</blockquote><p>解決的問題</p><ul><li>易於Test</li><li>Reuse 性高</li><li>商業邏輯與UI層/ViewModel層的分離</li></ul><p><strong>Redux</strong></p><p><strong>3 大原則</strong></p><ul><li>數據唯一性與唯獨性</li><li>更改數據唯一方法是發出Action</li><li>Reduce 是唯一接受 action 去執行更改數據</li></ul><p><strong>Action</strong></p><ul><li>更改數據的動作,進而衍生所有可執行的動作。</li></ul><p><strong>Reducer</strong></p><ul><li>Reducer: pure function, 變更數據的邏輯封裝在function 內，並且透過 input action 更改State</li></ul><p>Code Base</p><pre>Utility<br>    └── ViewModelComponents<br>            ├── BasicActionExcutorViewModel.swift<br>            ├── CellViewModelConfigureHandler.swift<br>            ├── ExcuteAction.swift<br>            └── TableViewModelProtocol.swift</pre><p><strong>ExcuteAction.swift</strong></p><pre>typealias Reducer&lt;State, Action&gt; = (inout State, Action)-&gt;()<br><br>protocol ActionExcutor {<br>    associatedtype State<br>    associatedtype Action<br>    func excute(_ action: Action)<br>    init(_ state: State, _ reducer: @escaping Reducer&lt;State, Action&gt;)<br>}</pre><p><em>Reducer&lt;State, Action&gt;</em></p><ul><li>Reducer: 封裝程式邏輯的閉包, 傳入帶有標籤 inout 的 State, 與當前的動作 Action 執行相應的邏輯</li><li>State: 存取的資料</li><li>Action: 將要執行的動作(一般使用 Enum 會比較好設計)</li></ul><p><em>ActionExcutor</em></p><ul><li>實際擁有Reducer, State, Action 實體的物件協議</li><li>可用於 MVVM, MVC, MVP 等架構</li></ul><p><strong>優點</strong></p><ul><li>State, Action 均為泛型，易於後期維護與擴充</li><li>ActionExcutor 設計成 Swift protocol(interface), 便於依賴注入設計</li><li>利於編寫測試</li></ul><p><strong>缺點</strong></p><ul><li>欠缺 Model 層的注入接口，不利於 Reuse 與 測試</li><li>補充：包含環境變數的引用（比如：登入狀態 等）</li><li>Action 無法串接成 Action Chain(註二), 將可能會破壞 State 單一更改數據的設計原則</li><li>補充：Action 也無法循環利用</li><li>處理異步任務需要在State額外調整為 Refence type</li></ul><p><strong>BasicActionExcutorViewModel.swift</strong></p><pre>class BasicActionExcutorViewModel&lt;State, Action&gt;: ActionExcutor {<br>    typealias State = State<br>    <br>    typealias Action = Action<br>            <br>    let reducer: Reducer&lt;State, Action&gt;<br>    <br>    private(set) var state: State<br>    <br>    required init(_ state: State, _ reducer: @escaping Reducer&lt;State, Action&gt;) {<br>        self.state = state<br>        self.reducer = reducer<br>    }<br>    <br>    func excute(_ action: Action) {<br>        reducer(&amp;state, action)<br>    }<br>}</pre><p><em>class BasicActionExcutorViewModel&lt;State, Action&gt;&gt;</em></p><ul><li>遵循 ActionExcutor 協議的 ViewModel, 提供編寫需求時作為父類繼承</li><li>建議：繼承樹(註三)不要超過2個，以免後期維護困難。</li></ul><p>註二: Action Chain- A (執行)&gt; B &gt; C &gt; A 註三: 繼承樹- A (繼承)&gt; B &gt; C &gt; D</p><p><strong>Swift_補充說明</strong> <br><br> <strong>inout</strong></p><pre>// example<br>func write(_ str: inout String) {<br>    // do not thing<br>}<br><br>var str = &quot;123&quot;<br><br>write(&amp;str)</pre><p>Swift的 <strong>inout</strong> 使用上與其結果看起來與C/C++ 或是相關系列語言的指標一樣，<br> 但是它們之間其實有根本上的不同。</p><blockquote>這邊討論的已 Value Type 為前提下的說明</blockquote><p><strong>指標</strong></p><ul><li>傳遞的是記憶體位子的容器。</li><li>記憶體內的數據有可能被更動。</li></ul><p><strong>inout</strong></p><ul><li>傳遞進去的還是一個複製體。</li><li>func 生命週期結束後將複製體得值塞回原本的記憶體內。</li><li>記憶體內的數據一定會被重新塞值（請參考 example)。</li></ul><p><strong>結論：</strong> 所以如果設計時使用 kvo/observe/willSet-didSet 這些觀察記憶體變化的觀察者， 要有意識的了解當變數被傳進 inout 的 method 內後，必定會被觸發。</p><pre>// example <br>class Container {<br>    var str: String = &quot;123&quot; {<br>        didSet {<br>            print(&quot;didSet&quot;)<br>        }<br>    }<br>}<br><br>func write(_ str: inout String) {<br>    // do not thing<br>}<br><br>write(&amp;Container().str)<br><br>// didSet</pre><p><a href="https://bestlifeforzhi.medium.com/redux-mvvm-2-swift-cd3ee3279f69">下一章：引入 Environment &amp;&amp; Action Composable</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b4655700b54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[More readable print in Swift.Dump]]></title>
            <link>https://bestlifeforzhi.medium.com/more-readable-print-in-swift-dump-3bb562c23e58?source=rss-9b825cda4fea------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bb562c23e58</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[combine]]></category>
            <dc:creator><![CDATA[Woody Liu]]></dc:creator>
            <pubDate>Thu, 07 Jul 2022 07:51:54 GMT</pubDate>
            <atom:updated>2022-07-07T07:51:54.590Z</atom:updated>
            <content:encoded><![CDATA[<p>More readable print in Swift.Dump</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7def006e49eb8d3fb473b5d1cab632c4/href">https://medium.com/media/7def006e49eb8d3fb473b5d1cab632c4/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bb562c23e58" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RedisJson Introduce]]></title>
            <link>https://bestlifeforzhi.medium.com/redisjson-introduce-6f1dbb37ab97?source=rss-9b825cda4fea------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f1dbb37ab97</guid>
            <dc:creator><![CDATA[Woody Liu]]></dc:creator>
            <pubDate>Fri, 20 May 2022 02:02:27 GMT</pubDate>
            <atom:updated>2022-05-20T02:02:27.478Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Redis Json 是專門為 Redis 增加 Json 存取的擴充，接下來我將介紹基本的指令應用</strong></p><p><strong>應注意事項：</strong></p><ul><li>需要額外安裝，目前還沒歸入Redis標準庫中。</li><li>存取的資料格式必須符合 JSON 規則。</li><li>透過 JSON 存的資料，只能透過 JSON.GET 取出。</li></ul><h4>Redis-CLI</h4><h4>JSON.SET</h4><p>Point</p><ul><li>value 必須符合JSON規則。</li><li>value 不得為 nil</li><li>str 如果為字串需要用單引號包起來，如:’””’</li></ul><h4>JSON 物件</h4><pre># object<br>json.set object $ &#39;{&quot;a&quot;:&quot;c&quot;,&quot;c&quot;:[1,2,3]}&#39;<br><br># 更改已存在key值<br>#{&quot;a&quot;:&quot;a&quot;,&quot;c&quot;:[1,2,3]}<br>json.set object $.a &#39;&quot;a&quot;&#39; <br><br># append element in array<br># {&quot;a&quot;:&quot;a&quot;,&quot;c&quot;:[1,2,3,4]}<br>json.arrappend object $.c 4<br><br># insert element in array<br># {&quot;a&quot;:&quot;a&quot;,&quot;c&quot;:[0,1,2,3,4]}<br>json.arrinsert object $.c 0 0<br><br># 插入新Key 與 值<br># {&quot;a&quot;:&quot;a&quot;,&quot;c&quot;:[0,1,2,3,4],&quot;d&quot;:12345}<br>json.set object $.d 12345<br><br># 刪除 object key<br># {&quot;a&quot;:&quot;a&quot;,&quot;c&quot;:[0,1,2,3,4]}<br>json.del object $.d<br><br># 刪除 object 內 array 元素<br># {&quot;a&quot;:&quot;a&quot;,&quot;c&quot;:[1,2,3,4]}<br>json.del object $.c[0]<br><br># 移除 array 最後一個<br># {&quot;a&quot;:&quot;a&quot;,&quot;c&quot;:[1,2,3]}<br>json.arrpop object $.c<br><br># nested json<br># 增加一個 key: d , value: &#39;{ &quot;e&quot;: &quot;f&quot;, &quot;g&quot;: [0,1,2]}&#39;<br># {&quot;a&quot;:&quot;a&quot;,&quot;c&quot;:[1,2,3],&quot;d&quot;:{&quot;e&quot;:&quot;f&quot;,&quot;g&quot;:[0,1,2]}}<br>json.set object $.d &#39;{&quot;e&quot;: &quot;f&quot;, &quot;g&quot;: [0,1,2]}&#39;<br><br># 更改 d 內部 e 的 value<br># {&quot;a&quot;:&quot;a&quot;,&quot;c&quot;:[1,2,3],&quot;d&quot;:{&quot;e&quot;:&quot;h&quot;,&quot;g&quot;:[0,1,2]}}<br>json.set object $.d.e &#39;&quot;h&quot;&#39;<br><br># get<br># {&quot;a&quot;:&quot;a&quot;,&quot;c&quot;:[1,2,3],&quot;d&quot;:{&quot;e&quot;:&quot;h&quot;,&quot;g&quot;:[0,1,2]}}<br>json.get object<br><br># get array<br># 1<br>json.get object $.c[0]<br><br># get nested<br># h<br>json.get object $.d.e<br><br># get nested array<br># 0<br>json.get object $.d.g[0]<br><br># 刪除整個key<br>del object</pre><h4>Array(陣列)</h4><pre># array<br># []<br>json.set array $ []<br><br># append<br># [0]<br>json.arrappend array $ 0<br><br># appen 複數<br># [0, 1, 2, 3]<br>json.arrappend array $ 1, 2, 3<br><br># insert<br># [0, 1, 2, 3, 4]<br>json.arrinsert array $ 4 4<br><br># insert 複數<br># [0,1,2,3,4,5,6,7,8,9]<br>json.arrinsert array $ 5 5 6 7 8 9<br><br># del<br># [1,2,3,4,5,6,7,8,9]<br>json.del array $[0]<br><br># pop<br># [1,2,3,4,5,6,7,8]<br>json.arrpop array<br><br># array count<br># 8<br>json.arrlen array<br><br># array 切片<br># [1,2,3,4,5,6]<br>json.ARRTRIM array $ 0 5<br><br># 取得<br># [1,2,3,4,5,6]<br>json.get array</pre><h4>String(字串)</h4><pre># string<br>json.set str $ &#39;&quot;&quot;&#39;<br><br># append str<br># str<br> json.strappend str $ &#39;&quot;str&quot;&#39;<br><br><br># 取得<br># str<br>json.get str</pre><p>其他JSON的型別指令操作與標準庫的指令相同，只要在前墜加上 json.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f1dbb37ab97" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[# RedisJson (mac os m1)]]></title>
            <link>https://bestlifeforzhi.medium.com/redisjson-mac-os-m1-98b390984e3b?source=rss-9b825cda4fea------2</link>
            <guid isPermaLink="false">https://medium.com/p/98b390984e3b</guid>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[m1-mac]]></category>
            <dc:creator><![CDATA[Woody Liu]]></dc:creator>
            <pubDate>Tue, 17 May 2022 04:17:26 GMT</pubDate>
            <atom:updated>2022-05-17T04:21:17.291Z</atom:updated>
            <content:encoded><![CDATA[<h3>RedisJson (mac os m1)</h3><h4>安裝</h4><p>網上查的到的文章大部分都是過時的做法，官方已經改變安裝方法。</p><h4>目前普遍有兩種作法</h4><pre># 找個資料夾將 redis json clone 下來 <br>git clone <a href="https://github.com/RedisJSON/RedisJSON">https://github.com/RedisJSON/RedisJSON</a></pre><h4>Docker(方法一)</h4><blockquote>使用 Docker 打開 RedisJson後，在Termianl鍵入</blockquote><pre>docker run -p 6379:6379 --name redis-redisjson redislabs/rejson:latest</pre><p>Note: 這方法我沒試過，因為我有更改 Redis根目錄位置</p><h4>Redis.conf 指定模組 (方法二)</h4><blockquote>這方法也是目前網上資源普遍能查到的方法 ，<br>但是官方有更改其編譯路徑，可以參考我的方法</blockquote><pre># first step:<br>cd path/to/RedisJson &amp;&amp; make</pre><pre># second step: (important)<br># 因為官方 make file 更改了路徑<br># 產出的二進制檔有區分 系統與硬體<br># 所以這邊建議直接打開對應的資料夾找 &#39;rejson.so&#39;<br># 比如我是 mac os m1 <br># 產出的 path: <br># ./bin/macos-arm64v8-release/rejson.so<br><br># 在桌面建立存放資料夾<br>mkdir ~/desktop/RedisConf &amp;&amp; touch ~/desktop/RedisConf/redis.conf<br><br># path to: 請改成正確路徑<br>find path/to/RedisJson/bin -type f -amin -5 -name &quot;rejson.so&quot; -exec echo &quot;loadmodule {}&quot; &gt; ~/desktop/RedisConf/redis.conf \;</pre><p>啟動 redis server 時指定conf: ~/desktop/RedisConf/redis.conf</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98b390984e3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Combine Basic Introduction]]></title>
            <link>https://bestlifeforzhi.medium.com/combine-basic-introduction-93101d6138de?source=rss-9b825cda4fea------2</link>
            <guid isPermaLink="false">https://medium.com/p/93101d6138de</guid>
            <dc:creator><![CDATA[Woody Liu]]></dc:creator>
            <pubDate>Thu, 17 Mar 2022 08:44:57 GMT</pubDate>
            <atom:updated>2022-03-17T08:44:57.955Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://developer.apple.com/documentation/combine">Combine</a> 基礎概要</h4><p><a href="https://bestlifeforzhi.medium.com/%E9%9F%BF%E6%87%89%E5%BC%8F%E7%B7%A8%E7%A8%8B-reactive-programming-1702ecb5e08f">上一篇</a> 以 <strong>Swift</strong> 角度介紹 <strong>響應式編程</strong> 。<br> 接下來我要介紹的是 <strong>Swift</strong> 原生的 <strong>響應式框架</strong> 基本架構與應用。</p><blockquote>如果之前你已經學會 <strong>RXSwift</strong> 框架的話，<br> 基本上 <strong>Combine</strong> 的應用對你來說可能只是幾分鐘的事情，<br> 因為 <strong>Combine</strong> 整體架構與 API 設計 很大一部分都致敬了 <strong>RXSwift</strong></blockquote><h4><strong>主要組件 Base Component</strong></h4><p>Combine 的架構主要由三個 <strong>Protocol</strong> 組合起來起來</p><ul><li>Publisher — 發布商（訊號的源頭)</li><li>Subscription — 訂閱商 (河道-類似經銷商的角色)</li><li>Subscriber — 訂戶 (接收到數據要執行的事情)</li></ul><p><strong>簡易關聯圖</strong></p><figure><img alt="關聯圖" src="https://cdn-images-1.medium.com/proxy/0*siiNLSzC5UnQ7SdC" /></figure><ol><li>Subscriber 向 Publisher 登記一個訂閱，獲取 Subscription。</li><li>Publisher 傳遞數據給 Subscription</li><li>Subscription 再將數據傳遞給 Subscriber</li></ol><p>基本應用情境下，不會直接接觸到 Publisher 與 Subscriber 的實體，Combine 框架已經將它們封裝在 API 內。<br> 我們只要管理好 Subscription 的生命週期即可。</p><p>接下來的介紹建議搭配 <a href="https://github.com/woodycatliu/Combine-Introduce-Resource">Playgraound</a></p><h4>Publisher</h4><p>從 Apple 推出 Combine 以後，也陸續替 Swift 基本數據庫中的成員增加 Publisher 以支援 Combine 的橋接。如：Timer, NoticationCenter, NSObject 與 基本型別等。</p><p><strong>請查看 Publisher 頁籤</strong></p><pre>var arr: [Int] = [0, 1, 2]<br>var str: String = &quot;ABCD&quot;<br>var int: Int = 1000<br><br>arr.publisher.printValue().store(in: &amp;bag)<br>str.publisher.printValue().store(in: &amp;bag)<br>int.words.publisher.printValue().store(in: &amp;bag)</pre><p>arr, str, int 均提供相應的 Publisher 數據流的傳遞。</p><blockquote>請試著執行比較差異</blockquote><h4>Subscriber</h4><p>Subscriber 為一段數據流的尾端，它封裝訂閱時所申明要執行的 closure。</p><p><strong>請查看 Subscriber 頁籤</strong></p><pre>var arr: [Int] = [0, 1, 2]<br>let toDo: (Int)-&gt; Void = { print($0 * 2) }<br><br>arr.publisher<br>    .sink(receiveValue: toDo)<br>    .store(in: &amp;bag)</pre><h4>Subscription</h4><p>Subscription 負責傳遞數據，它也掌握流的有效性。</p><p><strong>請查看 Subscription 頁籤</strong></p><pre>var arr: [Int] = [0, 1, 2]<br>var subscription: AnyCancellable? = arr.publisher<br>    .printValue()<br><br>subscription?.cancel()<br>// or<br>subscription = nil</pre><p>Subscription 結束生命週期 或是執行 <strong>cancel()</strong> 停止訂閱<br> ，未來有新的數據就不會再傳遞 。</p><h4>實體</h4><p>剛剛介紹了 Combine 三個主要協定，<br> 當然 Swift 團隊還提供很多遵守這些協定的實體，<br> 如：<a href="https://developer.apple.com/documentation/combine/just">Just</a> 、<a href="https://developer.apple.com/documentation/combine/future">Future</a>、<a href="https://developer.apple.com/documentation/combine/empty">Empty</a> …等。</p><p>接下來會關注 Combine 內最常用三大元件、</p><ul><li><a href="https://developer.apple.com/documentation/combine/passthroughsubject">PassthroughSubject</a></li><li><a href="https://developer.apple.com/documentation/combine/currentvaluesubject">CurrentValueSubject</a></li><li><a href="https://developer.apple.com/documentation/combine/published">Published</a></li></ul><p>它們直接提升 Swift 對屬性的監聽更加簡單容易，<br> 也是整個響應式框架的核心角色。</p><h4>PassthroughSubject</h4><p><strong>PassthroughSubject</strong> 提供發送值的功能，而本身不會存取這個值，就像一個郵差一樣的角色。</p><p><strong>請查看 PassthroughSubject 頁籤</strong></p><pre>let infailableSubject = PassthroughSubject&lt;Int, Never&gt; ()<br>let failableSubject = PassthroughSubject&lt;Int, MyError&gt;()<br><br>infailableSubject.send(1)<br>failableSubject.send(1)</pre><p>初始化 <strong>PassthroughSubject</strong> 要先定義 Output 與 Failure 的型別。</p><ul><li>Output : Int</li><li>Failure : Never, MyError</li></ul><blockquote>請試著執行</blockquote><h4><strong>補充</strong></h4><p><strong>Never</strong>：Combine 原生的 Error 型別，意思是Publisher 不會有錯誤狀況。<br> <strong>MyError</strong> ：MyError 是我自己定義的錯誤型別 (Sources/Error.swift )</p><pre>public enum MyError: Error {<br>    case someError<br>    case none<br>}</pre><h4>CurrentValueSubject</h4><p><strong>CurrentValueSubject</strong> 發送一個新值並存取起來。與 <strong>PassthroughSubject</strong> 不同的是 <strong>CurrentValueSubject</strong> 會 Cache 最新的值。</p><p><strong>請查看 CurrentValueSubject 頁籤</strong></p><pre>let infailableSubject = CurrentValueSubject&lt;Int, Never&gt; ()<br>let failableSubject = CurrentValueSubject&lt;Int, MyError&gt;()<br><br>infailableSubject.send(1)<br>failableSubject.send(1)</pre><blockquote>請試著執行</blockquote><h4>Published</h4><p><strong>Published</strong> 為一個屬性包裝器類型的 struct 。<br> 它會在其封裝的值 <strong>即將</strong> 改變時發送新值的訊號出去。</p><p><strong>請查看 Published 頁籤</strong></p><pre>@Published<br>var value: Int = 0<br>$value..sink(receiveValue: intClosure).store(in: &amp;bag)<br><br>value = 1 // 值接更改即可<br>value = 2</pre><blockquote>請試著執行與 CurrentValueSubject 比較。</blockquote><h4>補充</h4><p>範例 <strong>PublishedContainer</strong> 內封裝了一個帶有 <strong>@Published</strong> 標籤的 泛型 value 。<br> 因為 <strong>Published</strong> 必須在 class 內部才能定義。<br> 申明觀察帶有 <strong>@Published</strong> 標籤的值時，需要加上前墜 <strong>$</strong> 符號。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93101d6138de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[響應式編程 Reactive Programming]]></title>
            <link>https://bestlifeforzhi.medium.com/%E9%9F%BF%E6%87%89%E5%BC%8F%E7%B7%A8%E7%A8%8B-reactive-programming-1702ecb5e08f?source=rss-9b825cda4fea------2</link>
            <guid isPermaLink="false">https://medium.com/p/1702ecb5e08f</guid>
            <dc:creator><![CDATA[Woody Liu]]></dc:creator>
            <pubDate>Tue, 01 Mar 2022 07:14:15 GMT</pubDate>
            <atom:updated>2022-03-01T07:14:15.685Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>此篇將以 Swift 的角度去簡化 RP 理論的解釋</blockquote><p>對於 iOS/OS 開發前端，這兩年很頻繁的會聽到這個名詞。<br> 尤其是 Apple 推出 SwiftUI 與 Combine 以後，似乎 RxSwift 已經變成不是選修條件，越來越多公司在職缺條件中 Combine 或 RxSwift 是必要條件。<br> <strong>註：Combine/ RXSwift 是 RP 的高階封裝框架。</strong></p><h4>什麼是響應式編程(RP) ?</h4><p>相信很多人 Google 之後會更加模糊，尤其是閱讀完 <a href="https://en.wikipedia.org/wiki/Reactive_programming">Wikipedia</a> 艱深又空洞的理論介紹後，只看到一堆專業術語跟更多沒見過的名詞。</p><p><strong>別擔心</strong> 我會試著解釋這一切。</p><h4><strong>解決的問題</strong></h4><p>RP 解決 <strong>Data 與 View</strong> 是不同步的問題，<br> 在前端開發中，數據變化後再手動通知View 重新渲染，而在需求的增加與迭代開發後，最後就是**數據變化<strong>與</strong>刷新視圖**充斥在各處，交錯依賴難以維護。<br> <strong>(請見下方的偽代碼)</strong></p><pre>var userInfo = User()  <br><br>func fetchUserInfo() {  <br>      task.fetchAPI { data in<br>      guard let userInfo = try? decord(data) <br>           else { return }  <br>       self.userInfo = userInfo<br>       self.view.reload()<br>        }<br>    }<br><br>func changeUserName() {  <br>      userInfo.name = &quot;Jhonny&quot;  <br>      view.reload()  <br>    }<br><br>func changeUser() {  <br>       userInfo = newUserInfo()  <br>       view.reload()  <br>    }</pre><p>#### **實現的方法** 透過 **`資訊傳遞`** 的流動，拆分解藕每一個步驟。 想像一下河流有其 **`源頭`** 、 **`目的地`** 與每一個 **`節點`**， 透過這樣的劃分，這一切似乎就更好的去管理與控制河流的變化。</p><ul><li><strong>事件 Event</strong> (源頭)：remote url request、database request ….</li><li><strong>轉換 Operator</strong> (節點)：decord, data transform…</li><li><strong>綁定 Binding</strong> (目的地)：data cache、發送事件結束消息…</li><li><strong>觀察 Observe</strong> (目的地之後)：渲染畫面、下一個事件開始…</li></ul><h4>透過封裝後，把上面的邏輯組裝起來</h4><pre>fetchUserInfo() // Event<br>       .decord() // Operator<br>       .binding(on: self.userInfo) // 目的地<br>       <br>$self.userInfo.observe { self.view.reload } // Observe<br><br>func changeUserName() {  <br>      userInfo.name = &quot;Jhonny&quot;  <br>    }<br> func changeUser() {  <br>       userInfo = newUserInfo()  <br>    }</pre><ul><li>view 渲染的命令被收斂在對 userInfo 的觀察。</li><li>userInfo 的相關的變化邏輯都與 UI 層解藕。</li><li>data 從取得到變形被拆成一段一段去處理，便於管理代碼。</li></ul><h4>觀察者模式 vs 響應式編程</h4><p>OOP 的 <strong>觀察者模式</strong> 最常與 <strong>RP</strong> 做比較，<br> 那它們之間最大的差別可以用想要解決的問題與執行的位子的差別來區分。</p><h4>觀察者模式：</h4><blockquote>為了解決不同物件 1 對多的數據傳遞問題。</blockquote><h4>響應式編程</h4><blockquote>解決 <strong>Data 與 View</strong> 是不同步的問題</blockquote><p>所以在實作上， <strong>觀察者模式</strong> 會在 B 、C、D 物件中對 A 的觀察。 而 <strong>響應式編程</strong> 中，物件時常觀察自己內部某個值去執行下一個事件。</p><h4>響應式編程範圍</h4><p>在轉換成 <strong>RP</strong> 過程中，你可能會對範圍有所困惑。<br> 意思是整支APP的架構要做到什麼程度才算是響應式編程？</p><p>經過一段時間的練習與實作後，<br> 我認為 <strong>RP</strong> 如同其它的設計模式一樣，<br> 你可以小到一個 View 內所有的狀態變化流動，<br> 也可以大到整支 APP 所有事件與數覺得流動。<br> 所以在轉換初期可以先試著已一個 View 與其 ViewModel 做嘗試。</p><p><strong><em>下一章節，將會 Demo 由 Combine 所編寫的 RP</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1702ecb5e08f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>