<?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 Mohshin Shah on Medium]]></title>
        <description><![CDATA[Stories by Mohshin Shah on Medium]]></description>
        <link>https://medium.com/@mohshinshah?source=rss-984e4061cdfc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*uOvAcRebJxNk7oec.jpg</url>
            <title>Stories by Mohshin Shah on Medium</title>
            <link>https://medium.com/@mohshinshah?source=rss-984e4061cdfc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 23:35:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohshinshah/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[SwiftUI at Scale: Modernizing Legacy Enterprise iOS Apps]]></title>
            <link>https://mohshinshah.medium.com/swiftui-at-scale-modernizing-legacy-enterprise-ios-apps-f509340fcf66?source=rss-984e4061cdfc------2</link>
            <guid isPermaLink="false">https://medium.com/p/f509340fcf66</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[legacy-modernization]]></category>
            <category><![CDATA[mobile-engineering]]></category>
            <dc:creator><![CDATA[Mohshin Shah]]></dc:creator>
            <pubDate>Wed, 30 Jul 2025 10:31:54 GMT</pubDate>
            <atom:updated>2025-07-30T10:31:54.693Z</atom:updated>
            <content:encoded><![CDATA[<p>SwiftUI makes UI development feel magical. But turning that magic into a maintainable, testable, enterprise-ready codebase? That’s a different game.</p><blockquote>SwiftUI makes it easy to write <strong>expressive</strong> code — your job is to make it <strong>efficient</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v8tP-Bl5SYW8frLyR2K92g.jpeg" /></figure><p>As a Senior iOS Engineer with over a decade of Swift &amp; UIKit experience, I’ve seen teams get excited about <strong>SwiftUI</strong> — only to walk away when things didn’t “just work” at scale. And that’s understandable.</p><p>But here’s the truth: <strong>SwiftUI is no longer a toy. It’s a serious UI framework that’s ready for production — if you know how to approach it strategically.</strong></p><p>In this post, I’m sharing what I’ve learned about preparing your team and codebase for SwiftUI adoption in enterprise environments. This isn’t about syntax or views — this is about <strong>building sustainable, scalable SwiftUI architecture that can grow with your product and your team</strong>.</p><h3>🧭 1. Adoption is a Strategy, Not a Toggle</h3><p>One of the biggest mistakes I’ve seen is trying to go “all-in” on SwiftUI with an entire app rewrite. That’s a recipe for friction, especially if your team is UIKit-heavy.</p><p><strong>Instead, adopt SwiftUI incrementally:</strong></p><ul><li>Use UIHostingController to embed SwiftUI into existing UIKit flows.</li><li>Start with non-critical modules like onboarding, settings, empty states, or feature flags.</li><li>Define clear module boundaries so UIKit and SwiftUI don’t step on each other.</li></ul><blockquote>Your goal isn’t a rewrite — it’s evolution.</blockquote><h3>🎨 2. Invest in a SwiftUI-First Design System</h3><p>At scale, inconsistency compounds. Design debt becomes technical debt. And when your team grows, lack of reusable patterns becomes a blocker.</p><p>That’s where a <strong>SwiftUI-based design system</strong> comes in.</p><p>Build <a href="https://atomicdesign.bradfrost.com/chapter-2/">atomic components</a> (PrimaryButton, TitleLabel, CardView) using:</p><ul><li>ViewModifiers for consistent styling</li><li>@ViewBuilder for flexibility</li><li>Tokens for spacing, fonts, and colours aligned with design specs</li></ul><p>Go from 20+ variants of buttons to just 3 reusable, theme-aware SwiftUI components — fully testable and <strong>preview-able</strong>.</p><blockquote>A good design system turns opinions into implementation. A great one enforces it through SwiftUI.</blockquote><h3>🧱 3. Architect for Modularity and Reuse</h3><p>SwiftUI naturally encourages composition — but without clear boundaries, it can become messy fast.</p><p>Here’s what worked for us:</p><ul><li>Follow <a href="https://medium.com/ne-digital/mvvm-pop-to-deal-with-complex-ui-d4c5b76a92e1"><strong>MVVM</strong></a><strong> or </strong><a href="https://mohshinshah.medium.com/swiftui-apps-using-the-composable-architecture-tca-96a77917f236"><strong>TCA</strong> (The Composable Architecture) </a>to isolate logic and state.</li><li>Break large views into smaller subviews and reuse them across modules.</li><li>Use @Environment, protocol-based injection, and scoped ViewModels to avoid <strong>tight coupling</strong>.</li></ul><h3>⚙️ 4. Plan for Performance from Day One</h3><p>What feels fast in the simulator can choke in production — especially when dealing with large data sets or complex layouts.</p><p>🛠️ Here are a few performance rules of thumb:</p><ul><li><strong>Use </strong>EquatableView to avoid redundant re-renders.</li><li><strong>Be cautious with </strong>@State<strong> and </strong>@Bindingscoping matters.</li><li>Prefer LazyVStack over VStack for scrollable content.</li><li>Use <strong>Instruments</strong> to analyze body re-computation.</li></ul><h3>📦 5. Build Internal SwiftUI SDKs and UI Kits</h3><p>At the enterprise level, repeating common views is a waste. That’s where internal SwiftUI packages shine.</p><p>Bundle reusable components into a <strong>shared SPM package</strong>:</p><ul><li>Toasts, skeleton loaders, pill chips, error placeholders</li><li>Common state wrappers like AsyncContentView with loading/empty/error states</li></ul><p>Document each component and include live previews. This improves adoption and reduces bugs from misuse.</p><blockquote>Think of your internal UI kit as your SwiftUI “tool-belt.” Every tool is a productivity multiplier.</blockquote><h3>⚖️ 6. Embrace the Hybrid Reality</h3><p>Even with all its strengths, SwiftUI doesn’t replace UIKit completely — yet. Mixed codebases are normal.</p><p>You’ll need to:</p><ul><li>Use UIViewControllerRepresentable and UIHostingController wisely.</li><li>Clearly document bridging layers between SwiftUI and UIKit.</li><li>Define architectural boundaries to avoid tight coupling between paradigms.</li></ul><h3>🚀 Final Thoughts: Lead the SwiftUI Transformation</h3><p>SwiftUI is not just Apple’s future — it’s yours too.</p><p>If you’re a Staff or Principal iOS Engineer, <strong>your role isn’t just to adopt SwiftUI — it’s to guide your team through the adoption</strong>:</p><ul><li>Drive conversations with design and product.</li><li>Build the first system, then scale it.</li><li>Create resources. Mentor others. Lead by doing.</li></ul><blockquote>SwiftUI isn’t just a new UI framework — it’s a shift in how we think, build, and collaborate.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f509340fcf66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SwiftUI Apps using The Composable Architecture (TCA)]]></title>
            <link>https://mohshinshah.medium.com/swiftui-apps-using-the-composable-architecture-tca-96a77917f236?source=rss-984e4061cdfc------2</link>
            <guid isPermaLink="false">https://medium.com/p/96a77917f236</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[architecture]]></category>
            <dc:creator><![CDATA[Mohshin Shah]]></dc:creator>
            <pubDate>Thu, 06 Feb 2025 03:17:27 GMT</pubDate>
            <atom:updated>2025-02-06T03:17:27.597Z</atom:updated>
            <content:encoded><![CDATA[<h3>Simplifying State Management in <strong>SwiftUI</strong> with The Composable Architecture(TCA)</h3><blockquote>A system is not just a collection of components; It is a collection of interactions</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8LginVbtz5TBAIP5t2k4sA.png" /></figure><p>SwiftUI has redefined the way developers build UIs with its declarative syntax and reactive programming model. However, as apps grow in complexity, managing state and dependencies can become challenging. This is where <strong>The Composable Architecture (TCA)</strong> shines.</p><p>TCA, developed by the team at <a href="https://pointfreeco.com/">Point-Free</a>, provides a robust framework to structure SwiftUI applications. It emphasizes composability, testability, and scalability, making it a go-to choice for modern app development. In this article, we’ll explore the basics of TCA and how its core components interact to build <strong>maintainable</strong> and <strong>feature-rich</strong> applications.</p><h3>What is TCA?</h3><p><strong>The Composable Architecture</strong> is a design pattern and library for building applications in a consistent, modular, and testable manner. It’s well suited for <strong>SwiftUI</strong> because it aligns well with its declarative and reactive nature. But not limited to, You can use TCA with <strong>UIKit</strong> also.</p><p>Reference Link: <a href="https://github.com/pointfreeco/swift-composable-architecture">https://github.com/pointfreeco/swift-composable-architecture</a></p><p>TCA allows developers to:</p><ul><li>Manage <strong>state</strong> in a “centralized” manner.</li><li>Define <strong>business logic</strong> in small, “reusable” pieces called <strong>Reducers.</strong></li><li>Dependency injection (Built in) for <strong>testability and modularity</strong>.</li><li>Seamless composition of features into larger systems.</li></ul><h3>Core Components of TCA</h3><p>To understand the core components of TCA, Lets explore an example of a simple login feature. In this login feature we would like have username, password and a login button. If user clicks the login button we would like to make a dummy / real API call and shows an error if anything wrong. So keeping it very simple to understand. So for this system,</p><h4>1. State</h4><p>State represents the data that drives your application. It’s a Swift struct that holds all the mutable properties for a feature or an app. We will also have the initial values so no need to provide initial state values whenever we needed.</p><pre>struct LoginState: Equatable {<br>    var username: String = &quot;&quot;<br>    var password: String = &quot;&quot;<br>    var isLoading: Bool = false<br>    var isLoggingIn: Bool = false<br>    var errorMessage: String? = nil<br>}</pre><h4>2. Actions</h4><p>Actions represent events that can occur in the feature, such as user interactions or results from side effects.</p><ul><li><strong>IMPORTANT</strong>: Actions are dispatched from the <strong>view</strong> (meaning user facing) or from the <strong>side effects. That we will see in the following diagram.</strong></li></ul><pre>enum LoginAction: Equatable {<br>    case usernameChanged(String)<br>    case passwordChanged(String)<br>    case loginButtonTapped<br>    case loginResponse(Result&lt;Bool, String&gt;)<br>}</pre><figure><img alt="Understanding the state, actions and side effect" src="https://cdn-images-1.medium.com/max/1024/1*hrIoB3VZaCA0e-kr7a_fiw.png" /><figcaption>Diagram A. TCA Components</figcaption></figure><h4>3 Side Effects in TCA</h4><p>In <strong>The Composable Architecture (TCA)</strong>, side effects are treated as “first-class citizens.” They are handled explicitly, making your code more predictable and testable.</p><p><strong>Example of a Side Effect:</strong></p><p>Let’s say you’re building a <strong>Login feature</strong>:</p><ol><li>A user taps the “Login” button.</li><li>The app needs to <strong>call an API</strong> to verify their username and password.</li><li>This API call is a <strong>side effect</strong> because it:</li></ol><ul><li>Happens asynchronously.</li><li>Relies on an external server to respond.</li><li>Once the API responds, the result (success or failure) is sent back to the feature in terms of actions that feature understands, here it will be `handleLoginResponse`. eg. success or failure.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C44FKsGSmbIGAXwZZc7qCw.png" /></figure><h4>4. Reducer 🧠</h4><p>A <strong>reducer</strong> in TCA is like the <strong>brain of a feature or a component</strong>. It decides how your app’s <strong>state</strong> (data) should change when something happens (like a button tap) and whether any extra work needs to be done (like calling an API).</p><p>Imagine you’re managing a to-do list: If someone says,</p><ol><li><em>“Add a task,”</em> you update the list to include the new task.</li><li><em>“Mark this task as done,”</em> you find the task and mark it complete.</li><li><em>“What’s due tomorrow?”</em> you fetch that information for them.</li></ol><p>The reducer does the same thing in code:</p><ul><li><strong>Listen to actions:</strong> It hears requests like “usernameChanged” or “login button tapped.”</li><li><strong>Update the state:</strong> It modifies the app’s data (like adding updating text field value or password field value or showing error or success).</li><li><strong>Trigger side effects:</strong> It runs extra work (like fetching data or sending notifications or calling login API).</li></ul><p>In TCA, the reducer is just a structured way to organize this <strong>decision-making process</strong>, so your app stays predictable and easy to manage.</p><p>Reducer gets two input<br><strong>1. Action Triggered<br>2. Current State (Which reducer can change)</strong></p><p>For example, when user taps the button, Reducer should receive an action called `loginButtonTapped`, based on this action what reducer will do is, <br>it will change the current state, `isLoading` to true and will call a side effect for API call. That’s it.</p><p>As explained in SideEffect, <br>Once the API call side effect is done it will trigger the `handleLoginResponse`, which again will be received by reducer and reducer. For example if success, Reducer will receive a handleLoginResponse and it will change the state, isLoggedIn to true, error to nil.</p><p>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96a77917f236" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Mobile App Performance]]></title>
            <link>https://medium.com/ne-digital/optimizing-mobile-app-performance-1bed56fa8505?source=rss-984e4061cdfc------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bed56fa8505</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[reliability-engineering]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[mobile-app-performance]]></category>
            <dc:creator><![CDATA[Mohshin Shah]]></dc:creator>
            <pubDate>Wed, 13 Dec 2023 01:36:56 GMT</pubDate>
            <atom:updated>2023-12-13T01:36:56.544Z</atom:updated>
            <content:encoded><![CDATA[<p>In the fast-paced world of mobile applications, performance is paramount. Users expect apps to load quickly, respond instantly, and deliver a seamless experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y_nRj5odycMx_Ffs_-I27A.png" /><figcaption>Mobile App Optimization Techniques</figcaption></figure><h3>Performance Matters</h3><p>The performance of a mobile app directly influences user satisfaction and retention. As mobile devices become more advanced, users become less tolerant of sluggish performance. Therefore, optimizing your app for speed and responsiveness is not just a best practice; it’s a <strong>necessity. </strong>Lets understand this with an example of a trading cryptocurrency application.</p><h4><strong>Use case: The Critical Impact of App Performance in Trading Application</strong></h4><p>In a real-world scenario, consider a trader using an unoptimized trading app during a volatile market period. A <strong>delayed response</strong> in loading real-time market data can lead to executing a trade based on <strong>outdated information, resulting in a false transaction and potential financial losses</strong>. Moreover, if the app <strong>crashes</strong> during the transaction process, the user may inadvertently sell assets instead of making a desired purchase. This unintended action, coupled with the <strong>subsequent price drop</strong>, can lead to significant <strong>financial losses</strong> for the trader. In the fast-paced world of trading, where split-second decisions matter, the consequences of a poorly performing app extend beyond inconvenience — they can directly impact the financial well-being of the user.<br>Where in other hand, An optimized app, with faster <strong>response times</strong> and <strong>reliability</strong>, becomes paramount in preserving the integrity of trading decisions and <strong>safeguarding</strong> users from unintended and <strong>costly errors</strong>.</p><p>To meet these expectations, developers must employ a range of optimization techniques. In this comprehensive guide, we’ll explore key strategies to enhance the performance of your mobile app.</p><ol><li><strong>Performance Measurement: 📊</strong></li><li><strong>Code Optimization: 🛠️</strong></li><li><strong>Network Optimization: 🌐</strong></li><li><strong>UI/UX Optimization: 🎨</strong></li><li><strong>Memory Management: 🧠</strong></li><li><strong>Testing and Profiling: 🧪</strong></li><li><strong>Updates and Maintenance: 🔄</strong></li></ol><p>Let’s explore each and every item one by one in in details.</p><h3>1. Performance Measurement</h3><p>Measuring the performance of your mobile app is the first step towards optimization. By understanding key metrics, developers can identify areas that require improvement and ensure a smoother user experience.</p><h4>Techniques:</h4><ul><li>Performance measurement involves utilizing dedicated tools to assess key metrics such as load time, response time, and resource utilization. In iOS development, Xcode’s Instruments provides a suite of powerful tools for real-time analysis, offering insights into <strong>CPU usage, memory allocations </strong>etc.<br>Using tools like Android Profiler, XCode Instruments allow developers to monitor and profile various aspects of the app’s performance, facilitating the identification of bottlenecks and areas in need of optimization.<br>Apart from this inbuild tools, There are many tools avaialble to do the performance measurement for the apps. eg. Charles Proxy, Appium, Firebase Performance Monitoring, Grafana etc.</li></ul><h4>Benefits:</h4><ul><li><strong>Identify Bottlenecks</strong>: Pinpoint areas of your app that require optimization.</li><li><strong>Optimize resource usage:</strong> Understand how your app utilizes resources like <strong>CPU </strong>and<strong> memory</strong>.</li><li><strong>Real-time Monitoring:</strong> Track performance metrics during development and testing phases.</li></ul><h3>2. Code Optimization</h3><p>Optimizing code improves execution speed and reduces resource consumption. This section covers minification, compression, and efficient asset management. Reducing app binary size etc.</p><h4>Techniques:</h4><ul><li>Tools to use for Minifies, obfuscates, and optimizes the code.</li><li>Compiler level optimizations during the build process. eg. LTO (Link Time Optimization) etc.</li></ul><h4>Benefits:</h4><ul><li><strong>Reduced File Sizes:</strong> Smaller codebase results in faster downloads and improved load times.</li><li><strong>Enhanced Execution Speed:</strong> Optimized code executes more efficiently.</li></ul><h3>3. Network Optimization</h3><p>Efficient network usage is crucial for a responsive app. This section covers caching, data compression, and asynchronous loading.</p><h4>Techniques:</h4><ul><li>A powerful HTTP client custom build or third party that supports caching and compression.</li><li>Implementing paginated API calls to avoid loading all data once.</li><li>Implementing <strong>Circuit Breaker design pattern</strong> or <strong>Exponential Back-Off</strong> mechanisms.</li><li>Offline or disk level storage for Image or Data</li></ul><h4>Benefits:</h4><ul><li><strong>Faster Loading Times:</strong> Reduced network requests lead to faster content delivery.</li><li><strong>Bandwidth Efficiency:</strong> Compressed data and asynchronous loading improve bandwidth utilization.</li></ul><h3>4. UI/UX Optimization</h3><p>Optimizing the user interface and experience ensures smooth app interaction. This section covers render performance, animation optimization, and responsive design.</p><h4>Techniques:</h4><ul><li>Analyze UI components and hierarchies, debug and optimize UI elements in real-time using view debugger tools <br>eg Android (Android Studio Layout Inspector), iOS (Xcode View Debugger) etc.</li></ul><h4>Benefits:</h4><ul><li><strong>Smooth Animations:</strong> Optimized UI elements contribute to smoother animations.</li><li><strong>Consistent User Experience:</strong> Responsive design ensures a seamless experience across devices.</li><li><strong>List UI optimizations:</strong> Prefetching for image downloads for list UIs Pagination, Reusable list views</li></ul><h3>5. Memory Management</h3><p>Efficient memory usage is crucial for app stability. This section covers memory leak detection and background process management.</p><h4>Techniques:</h4><ul><li>Detect memory leaks and visualize and analyze object relationships in memory.</li></ul><h4>Benefits:</h4><ul><li><strong>Stability:</strong> Effective memory management prevents <strong>crashes</strong> and enhances <strong>app stability</strong>.</li><li><strong>Resource Efficiency:</strong> Proper background process management improves overall resource usage.</li></ul><h3>6. Testing and Profiling</h3><p>Testing and profiling ensure your optimizations work as intended. This section covers performance testing and profiling tools.</p><h4>Techniques:</h4><ul><li>Add unit testing and UI testing and use the test result for the coverage percentages. Eg. Sonar</li><li>Implement testing result gathering at the code review pipelines in the CI/CD.</li></ul><h4>Benefits:</h4><ul><li><strong>Reliability</strong>: Testing ensures new optimizations do not introduce regressions.</li><li><strong>Identification of Issues</strong>: Profiling tools help identify and fix performance bottlenecks.</li></ul><h3>7. Dependency Updates and Maintenance</h3><p>Regular updates and maintenance contribute to long-term performance. This section covers the importance of keeping your app and dependencies up-to-date and secure from any breaches or vulnerabilities.</p><h4>Techniques:</h4><ul><li>Dependency management and updating eg. Gradle, Carthage, Cocoapods, SPM etc</li><li>Use of feature flagging techniques to deliver changes silently at granular well tested pace rather than all at once approach.</li><li>Static and dynamic analysis using Security Scanners: Scan dependency for any security issues and vulnerabilities. You may consider tools like <a href="https://github.com/MobSF/Mobile-Security-Framework-MobSF">MobSF</a>, <a href="https://github.com/aquasecurity/trivy">Trivy</a>, <a href="https://owasp.org/www-project-mobile-app-security/">OWASP</a> etc</li></ul><h4>Benefits:</h4><ul><li><strong>Security</strong>: Updates often include security patches.</li><li><strong>Vulnerability Detection</strong>: Security scanners can identify and report security vulnerabilities in the code, libraries, and dependencies of mobile applications. Addressing these vulnerabilities early in the development lifecycle helps prevent security breaches that could negatively impact performance. It helps to enhance the user trust.</li><li><strong>Performance Improvements</strong>: Ongoing maintenance enhances performance with each release.</li><li><strong>Modularity: </strong>Modular application development without blocking others</li></ul><h3>Conclusion</h3><p>Optimizing mobile app performance is an ongoing process that involves various strategies and tools. By measuring, optimizing, and continuously testing, developers can ensure their apps deliver a seamless and responsive experience on both Android and iOS platforms. Stay proactive, leverage the right tools, and prioritize user experience in every optimization effort.</p><p>Thank you reading 📖 and Happy Coding 🧑‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bed56fa8505" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ne-digital/optimizing-mobile-app-performance-1bed56fa8505">Optimizing Mobile App Performance</a> was originally published in <a href="https://medium.com/ne-digital">NE Digital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modular Mobile App Development: Versioning Modules]]></title>
            <link>https://medium.com/ne-digital/modular-mobile-app-development-versioning-modules-41489fb5f493?source=rss-984e4061cdfc------2</link>
            <guid isPermaLink="false">https://medium.com/p/41489fb5f493</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[release-management]]></category>
            <category><![CDATA[semantic-versioning]]></category>
            <category><![CDATA[anroid-app-development]]></category>
            <dc:creator><![CDATA[Mohshin Shah]]></dc:creator>
            <pubDate>Mon, 17 Apr 2023 04:20:44 GMT</pubDate>
            <atom:updated>2023-04-17T04:20:44.355Z</atom:updated>
            <content:encoded><![CDATA[<p>When developing mobile apps with Swift, Kotlin, Dart or etc, having a clear versioning strategy in place is crucial for keeping track of changes and updates. In this post, we will explore some common versioning strategies for mobile apps.</p><ol><li><strong>Semantic Versioning</strong></li><li><strong>Date-Based Versioning</strong></li><li><strong>Sequential Versioning</strong></li></ol><h3>Semantic Versioning or SemVer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IUZrUWM7bp7wNh_254QwdA.png" /><figcaption>major.minor.patch</figcaption></figure><p>Semantic Versioning, also known as SemVer, is a widely used versioning strategy that uses a three-part version number in the format of “major.minor.patch”. The major version number indicates major changes that are not backwards-compatible, the minor version number indicates new features or functionality added in a backwards-compatible manner, and the patch version number indicates bug fixes and minor changes. <br>There can be further deeper versioning details such as <em>build, revision etc., </em>but I will keep this to the basics for this article.</p><p>For example, a version number of “5.41.2” would represent a major version of 5, a minor version of 41, and a patch version of 2. It is essential to communicate the meaning of each part of the version number to users when using SemVer.</p><p>Most apps in the app stores, including standard apps like Calendar, Contacts, and Messages on iOS, and similar apps on Android, use semantic versioning or a variant of it.</p><h4>Conventional Commits for Semantic Versioning</h4><p>changes to the major, minor, or patch version number are determined by the nature of the changes made in the software. The <a href="https://www.conventionalcommits.org/en/v1.0.0-beta.2/">Conventional Commits </a>specification provides a standardised way to indicate the type of change made in a commit message, which can then be used to determine the appropriate version number update.</p><ul><li>Use imperative language: Add login test ✅, not Added login test ❌</li><li>Begin the summary line with a type <strong>prefix <br><em>eg. feat, fix, docs, style, refactor, test, chore, or perf<br>Please check the link for </em></strong><a href="https://www.conventionalcommits.org/en/v1.0.0-beta.2/">Conventional Commits</a> for more details</li><li>Include a more detailed description of the changes being made in the commit message body if needed</li><li>Use a footer section to include any additional information related to the change, such as links to related issues or pull requests.</li></ul><p>By following the <strong>major.minor.patch</strong> pattern and using <a href="https://www.conventionalcommits.org/en/v1.0.0-beta.2/"><strong>Conventional Commits</strong></a>, developers can communicate the nature of their changes in a clear and consistent way, which helps other developers understand the impact of changes and makes it easier for app releases.</p><h3>Date-Based Versioning or <strong>CalVer</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDDdmVkX-3smfYp5DuuNHw.png" /></figure><p>Date-based versioning uses a date or timestamp as the version number, making it useful for apps that have a regular release schedule, such as monthly or quarterly. For example, a version number of “2023.04.07” would indicate that the app was released on April 07, 2023.</p><p>While date-based versioning helps users understand the age of the app, and when it was last updated, it may not be appropriate for apps that receive more frequent updates or have an irregular release schedule.</p><p>Normally, no standard mobile app uses this, but you can find this in For example, in Ubuntu 21.10 was released in October 2021. This system provides a clear indication of the age of the release and makes it easy to track changes over time.</p><h3>Sequential Versioning</h3><p>Sequential versioning uses a simple incrementing number as the version number, which can be useful for smaller apps or modules with infrequent updates. For instance, an app might start with version number “1” and increment to “2”, “3”, and so on with each release.</p><p>References:<br><a href="https://ubuntu.com/blog/ubuntu-21-10-has-landed">https://ubuntu.com/blog/ubuntu-21-10-has-landed</a><br><a href="https://en.wikipedia.org/wiki/Software_versioning">https://en.wikipedia.org/wiki/Software_versioning</a><br><a href="https://www.conventionalcommits.org/en/v1.0.0-beta.2/">https://www.conventionalcommits.org/en/v1.0.0-beta.2/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41489fb5f493" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ne-digital/modular-mobile-app-development-versioning-modules-41489fb5f493">Modular Mobile App Development: Versioning Modules</a> was originally published in <a href="https://medium.com/ne-digital">NE Digital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modular Mobile Development: Updating modules gracefully]]></title>
            <link>https://medium.com/ne-digital/modular-mobile-development-updating-modules-gracefully-4cda2d2d0869?source=rss-984e4061cdfc------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cda2d2d0869</guid>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[modular-architecture]]></category>
            <dc:creator><![CDATA[Mohshin Shah]]></dc:creator>
            <pubDate>Mon, 17 Apr 2023 04:18:43 GMT</pubDate>
            <atom:updated>2023-04-17T04:18:43.167Z</atom:updated>
            <content:encoded><![CDATA[<h3>Modular Mobile App Development: Updating modules gracefully</h3><p>How to update public APIs gracefully with less painful build issues on the usage side?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XWaECEbwCdbx9Vh3ujDrcw.png" /><figcaption>***Red arrows denote may fail due to changes released.</figcaption></figure><p>Updating public APIs can be a challenging task for module developers. However, there are some best practices that you can follow to reduce build issues and prevent failures on the usage side. Here are some tips for updating public APIs in a way that minimises the risk of build issues and failures:</p><ol><li>🆕 <strong>Use of `available` or `minSdkVersion` attributes</strong></li><li>📝 <strong>Use default values for optional or backwards-compatible values</strong></li><li>🚫 <strong>Use Deprecation</strong></li><li>📑 <strong>Provide Migration Guides</strong></li><li>📱 <strong>Use a demo app in the module itself to test and consume</strong></li><li>🎚️ <strong>Versioning</strong></li></ol><h3><strong>1. Use of `available` or `minSdkVersion` attributes</strong></h3><p>The <strong>available</strong> in Swift or <strong>minSdkVersion </strong>in Android<strong> </strong>attribute is used to indicate the availability of a particular API on different platforms and versions of the operating system. <br>For example, if you want to start using async/await in your Swift module, you also must be aware that it is supported by Xcode 13 onwards, which includes Swift 5.5. Here you may introduce older use case failures. So using an `available` with a deprecation on the older function will really be a win-win.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1GF3tKYWnGGRhs1StXTXMA.png" /><figcaption>Using a backward compatible variant and deprecation to handle use cases that might fail because of the module update</figcaption></figure><h3><strong>2. Use default values for optional parameter values or backwards-compatible values</strong></h3><p>Using default parameters is a useful technique for module developers who need to add new parameters to existing functions or methods without causing build issues for users who are already using the API.</p><p>By providing a default value for the new parameter, developers who are using the API will not need to modify their existing code unless they need to take advantage of the new parameter.</p><p>Here’s an example of how you can use default parameters to avoid build issues when adding a new parameter to an existing method</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_bzXzN1Ob8VIY6xII7vWg.png" /><figcaption>Backward compatibility using default values for public API changes to avoid failures</figcaption></figure><h3><strong>3. Use Deprecation</strong></h3><p>Before removing any public APIs, it is a good idea to deprecate them first. Deprecation means that you mark the API as obsolete or discouraged to use in the future. This will give developers using your module enough time to update their code before removing the API. Deprecation can also help you identify which APIs are still being used so that you can prioritise updates and maintenance.</p><h3><strong>4. Provide Migration Guides</strong></h3><p>When you update your public APIs, it is important to provide migration guides that explain how to update the code. Migration guides should include step-by-step instructions on how to update the code, including changes to function signatures, parameter types, and return types. Providing clear migration guides can help prevent build issues and ensure that developers can update their code with minimal difficulty.</p><h3><strong>5. Use a demo app in the module itself to test and consume</strong></h3><p>Before releasing an updated version of your module, it is important to test your public APIs thoroughly. This means that you should run unit tests and integration tests on all of your public APIs to ensure that they work as expected. Testing can help you identify any potential build issues or failures before they reach your users.</p><h3><strong>6. Versioning</strong></h3><p>Another best practice for updating public APIs is to use versioning. Versioning involves creating distinct versions of your module that include specific sets of APIs. Versioning allows developers to use a specific version of your module that is compatible with their code. When you update your public APIs, you can create a new version of your module and clearly document the changes and compatibility requirements for that version.</p><p>In summary, updating public APIs can be a challenging task. And It is inevitable to get failures for the modules, and at some point, you will HAVE breaking changes which we can handle by releasing a major update. However, following these best practices can help you minimise build issues and prevent failures at the usage side for minor releases and ongoing development.</p><p>By using deprecation, providing migration guides, testing thoroughly, and versioning your module, you can ensure that your users can update their code with minimal difficulty and continue to use your module without any interruption.</p><p><strong>References</strong><br><a href="https://swiftindepth.com/articles/async-await-modules/">https://swiftindepth.com/articles/async-await-modules/</a><br><a href="https://www.avanderlee.com/swift/available-deprecated-renamed/">https://www.avanderlee.com/swift/available-deprecated-renamed/</a><br><a href="https://www.swiftbysundell.com/articles/default-arguments-in-swift/">https://www.swiftbysundell.com/articles/default-arguments-in-swift/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cda2d2d0869" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ne-digital/modular-mobile-development-updating-modules-gracefully-4cda2d2d0869">Modular Mobile Development: Updating modules gracefully</a> was originally published in <a href="https://medium.com/ne-digital">NE Digital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modular Mobile App Development: Coding Guidelines]]></title>
            <link>https://medium.com/ne-digital/modular-mobile-app-development-coding-guidelines-98cb235c740a?source=rss-984e4061cdfc------2</link>
            <guid isPermaLink="false">https://medium.com/p/98cb235c740a</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[source-code]]></category>
            <category><![CDATA[modular-architecture]]></category>
            <dc:creator><![CDATA[Mohshin Shah]]></dc:creator>
            <pubDate>Sun, 16 Apr 2023 14:45:53 GMT</pubDate>
            <atom:updated>2023-04-16T14:46:38.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b607C5CdyVE7JJFBSucClg.png" /></figure><p>As a mobile developer, one of the most important aspects of your job is creating reusable modules that can be integrated into other applications. Whether you are developing modules for CocoaPods, Carthage, SPM, Frameworks or Git submodules etc., there are some tips and guidelines that you should follow to ensure that your modules are of the highest quality and can be easily integrated into other projects.</p><h3><strong>1. Keep it Modular</strong></h3><p>One of the most important aspects of developing a module is keeping your code modular. This means that you should avoid creating massive files with many lines of code. Instead, you should break your code up into smaller, more manageable files. This will make it easier for other developers to understand your code and to make changes if necessary.</p><h3><strong>2. Documentation</strong></h3><p>Another important aspect of developing a module is documenting your code. This means that you should add comments to your code that explain what each part of the code does. This will make it easier for other developers to understand your code and to make changes if necessary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wNq3j5-gD8w43GngDWw5hg.png" /></figure><h3><strong>3. Use Descriptive Naming Conventions</strong></h3><p>When naming your classes, functions, and variables, it is important to use descriptive naming conventions. This means that you should use names that clearly describe what each part of your code does.</p><p>For example, if you create a networking module, you might name your classes and functions “NetworkManager” or “sendRequest.” If it is for Analytics, it should be “AnalyticClient” and “trackEvent”.</p><h3><strong>4. Use Public Interfaces with care. If not needed, go private</strong></h3><p>When developing a module, exposing a public interface that other developers can use to interact with your module is important. This means that you should only expose the parts of your code that other developers need to use, and you should hide the rest. This will make it easier for other developers to use your module and will also make it less likely that they will introduce bugs or other problems.</p><h3><strong>5. Test Test Test</strong></h3><p>Finally, it is important to test your module thoroughly before releasing it to other developers. This means that you should create unit tests that cover all of the functionality of your module. This will help you to identify any bugs or other issues before other developers start using your module.</p><p>In conclusion, developing a module for Carthage or SPM can be a challenging task, but following these tips and guidelines can help you to create high-quality, reusable modules that other developers will be able to use easily. By keeping your code modular, documenting your code, using descriptive naming conventions, using public interfaces, and testing your module thoroughly, you can ensure that your module will be a valuable asset to other iOS Swift developers.</p><h3>What next?</h3><p>These guidelines really help in developing and making a healthy module. But what care is to be taken when the modules need updates, changes, fixes, renaming etc.? You can check out my next article in the same context.</p><h4><strong>How to update public APIs such that minimal build issues and fails at the usage side?</strong></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98cb235c740a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ne-digital/modular-mobile-app-development-coding-guidelines-98cb235c740a">Modular Mobile App Development: Coding Guidelines</a> was originally published in <a href="https://medium.com/ne-digital">NE Digital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MVVM + POP to deal with complex UI]]></title>
            <link>https://medium.com/ne-digital/mvvm-pop-to-deal-with-complex-ui-d4c5b76a92e1?source=rss-984e4061cdfc------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4c5b76a92e1</guid>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[protocol-oriented]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Mohshin Shah]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 00:09:18 GMT</pubDate>
            <atom:updated>2022-09-07T00:09:18.278Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QNYHdIu0galGND1LeT1rRQ.png" /></figure><p>How to use MVVM with POP to code and solve issues while designing and coding complex UIs. with examples.</p><p>Hello 🙋,<br>Firstly,<br>MVVM stands for Model View ViewModel<br>POP stands for Protocol Oriented Programming<br>If this title doesn&#39;t ring a bell for this abbreviations😵‍💫, <br>Nothing to worry, I will cover the basic foundation and ideas.</p><h3><strong>MVVM? Why not the MVC for iOS Development ?</strong></h3><p>While doing iOS devs, you must be knowing that UIViewController comes with a View in built. Now you wonder what is an issue with that. <br>Well, there are a few things which it evolves doing so if you go with this.</p><ol><li>As your view is inside your controller, and all UI and controlling logic like making network calls, data base ops, formatting data etc. happens inside where the view is. (Now someone would argue that we can use a separate class to make network , db ops etc but still your VC stays the main hero to initiate this). So at the end of the day what happens if your stakeholders or business team decides to change the UI or want to show profile page from somewhere else not from this screen, YOU WILL END UP changing UIViewController again and again for UI changes</li><li>What if you want to write test cases for the business logic for this screen like showing data is correct, how to handle a not-logged in user, tracking analytics for a specific click. <em>WE CANT</em> ! coz it’s not possible until we create a UIViewController. And moreover if you are using a UIStoryboard, You will end up with a lot of work arounds.</li><li>Plus, your UIViewController becomes bigger and bigger when you add more screens, routing, more logic, (Some says we may use helper and wrappers but then Point 2 😐)</li></ol><p>So what can be done to solve this kind of problems, We can use few architecture pattens like MVVM, MVP, Clean, Viper, in all of this MV<strong>*</strong> patterns, your * is a component which tries to break this View dependency of a UIViewController. Either by providing data what view needed without putting it inside VC or Moving Routing decision to some where else and ultimately makes your UIViewController a VIEW component. I repeat again, making your UIViewController a simple VIEW component.</p><p>So now you are eager to ask me, what are the advantages ? This will make your view a dumb view component, meaning not having any business logic inside, no control of doing stuff, routing etc. HENCE we have separated our view, woah! and now we can test our other components ,as usual without creating a view. Plus nothing gets affected if we change UI or View. Is not that great ? Like if you get a task to change UITableView to UICollectionView, and you are like, OKAY, Easy to do. Lol.</p><blockquote><strong>Basic Idea is Separation of Concerns, no matter if its an MVVM or any other (MV-*) patterns</strong></blockquote><h3>M-V-VM: M-V-(<strong><em>ViewModel -&gt; Model For View)</em></strong></h3><p>Anyways, That was some idea about MVVM. MVVM stands for Model View ViewModel. And if you are confused, let me clarify, in the MV* architectures I explained above, here the * is our ViewModel. A model for View, a model to which has data for view. OR OR A model which avails <strong>formatted data </strong>for view 😉.</p><p>Now I hope you are clear about what MVVM does and what are the pros, cons.</p><p>So There are a couple of things I have derived is,</p><ol><li><strong>View</strong> Component (Note: UIViewController is View) can have a ViewModel inside and it relies on it only.</li><li><strong>ViewModel</strong>: A component responsible for doing all the work and prepares data for View to consume. A ViewModel can have a <strong>Model</strong> in it</li><li><strong>Model: </strong>Well, nothing changed here, a data model or a value type</li></ol><p>Question: Oh Wait a moment, Does this mean MVVM is an architecture pattern ?<br>- I would say its more like solving the UI level separation so it is solving an issue which is the View(Interface) separation from Controller (Here controller is a C in MVC). It is not solving any other aspect of your application though. Hence it is not exactly an application architecture pattern but a UI design pattern.</p><p>I hope the above has cleared the idea about MVVM for you. Let’s see what is this POP thing is. If you are an iOS developer you must have heard of Protocols. And if some other coding background it is the same as Interfaces. <br>Interface/Protocols/Abstraction this all refers to the same idea of solving many things. If you heard of <strong>SOLID principles</strong>, many of the principles eg. <a href="https://mohshinshah.medium.com/solid-open-close-principle-ocp-1ee22ae940ea">Open/Close</a>, <a href="https://mohshinshah.medium.com/solid-liskov-substitution-principle-lsp-9e75d7a3f767">Liskov Substitution</a>, <a href="https://mohshinshah.medium.com/solid-dependency-inversion-principle-dip-929da9af6672">Dependency Inversion</a> etc have this Interface/Protocol/Abstraction idea at the core. You may check my series of SOLID principles for more detailed information <a href="https://mohshinshah.medium.com/solid-principles-d7cef30d9fa0">here</a>.</p><p>Now with the traditional SuperClass-SubClass, there are some issues, you may have also experienced eg. Empty Function implementations or fatal error with “subclass must implement it”, or a down casting. You may check this if interested. <a href="https://developer.apple.com/videos/play/wwdc2015/408/">https://developer.apple.com/videos/play/wwdc2015/408/</a>.</p><p>Protocols in swift actually gives more power like,</p><ol><li>You can create a protocol and have an extension on this protocol to have a default implementation.<br>- <strong><em>Doesn’t this sound like a super class implementation. You have an implementation that all subclass will have by default.</em></strong></li><li>Protocols allows you to write an extendible code. Eg. You may have extension on the Existing classes, enums, etc and add more functionalities to it without subclassing it.<br>- <strong><em>This is amazing, no? You can have a similar thing like subclassing without actually doing it.</em></strong></li><li>Multiple inheritance. Either You can make a protocol which inherit from a protocol or multiple protocols or you can conform multiple protocols which solves the multiple-inheritance issue. Please check example for the in the images given below.<br><strong><em>- Which gives you flexibility and extendibility for your code</em></strong></li></ol><p><strong>Look at this Array code in Swift codebase, Extendible and No subclassing at all.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AiCteoAGURKEmWYxZ81hZQ.png" /></figure><p><strong>Protocol Inheriting another protocols.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_JjzghzAdbPBFEj5YZmvkw.png" /></figure><p>Yes This is the <strong>POP</strong> — <strong>Protocol Oriented Programming</strong>. Using protocol to write the code not using class hierarchies. It would solves many issues. Creating protocols grouping similar behaviour methods in to one. “High Cohesion, Loose Coupling”<br>Later you can either compose this protocols to one or a protocol which inherits other protocols for better naming. Check this `Codable` Protocol in swift.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XxrFXx1A5jv100DKirUn7g.png" /></figure><p>Now I really hope you understand the MVVM and POP ideas. Let’s see how can we make our ViewModels more POP way.</p><p>Let’s understand this with an example. There is an UI given as below and you would like to write the code for this list. What would be the approach first.</p><figure><img alt="Example mobile UI. Write a code to cater this UI" src="https://cdn-images-1.medium.com/max/1024/1*Z24L-SOjQ_rVwsv3DwqXSQ.png" /></figure><p>Okay first you would assume there would be a <strong>ContactListViewModel </strong>and it will give you the data what’s necessary for this listing.and There will be one ContactCellViewModel which will give the data for each cell UI. So far so good. It is surely a good way to do this. <br>1. ContactListViewController depends on a ContactListViewModel<br>2. ContactTableViewCell has a ContactCellViewModel</p><p>All good. Nothing wrong in that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YCC_LEV8wLxUnpiI9DcgVw.png" /><figcaption>Diagram 1</figcaption></figure><p>But the things get complex when you have heterogeneous UI in the list. Let’s see another example of list UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*KJuCQHKSvGfNphCu2OXHlA.png" /><figcaption>Complex UI, can not use the same ViewModel to render all the cells, because they are heterogeneous.</figcaption></figure><p>In this UI, we can not use an array of CellViewModels to represent cells, as all the cells have different UI and behaviour and in that matter we cant even use a single CellViewModel to represent all the cells. And if we do that it will end up writing the unnecessary or blank codes for the cells which doesn&#39;t need other features. Eg, Date selection for first Title input cell. <br>So how to solve this issue ?</p><p>Yes got me correct, Using a POP</p><p>As we know that ViewModel has everything that a View requires, why not we make this mapping using an abstraction. Using a protocol. Like for the first cell only one thing is needed which is Title text. (lets not discuss the input, validation etc else it would be another topic).</p><h3>Using a Presentable Protocol</h3><p>First of all lets create one Protocol/Interface which represent the all the cells itself and define common things there. a `Presentable` protocol<br>eg. `<strong>TaskListItemPresentable</strong>`<strong> </strong>and as we can see all the cells have a title. Lets define it here.</p><figure><img alt="Defining the presentable protocols for a view. Whatever data a view would require to render." src="https://cdn-images-1.medium.com/max/1024/1*NZbG_Qvaw6Y5bCUxgNPGyw.png" /><figcaption>Defining the presentable protocols for a view. Whatever data a view would require to render.</figcaption></figure><p>And then ListViewModel can now have the array of `<strong>TaskListItemPresentable</strong>`.</p><p>Now create the respective ViewModels to conform this protocol and provide necessary data.</p><figure><img alt="Conforming the presentable to the actual viewModel to provide actual implementation." src="https://cdn-images-1.medium.com/max/1024/1*qC_022aQsL68R8aZm8eqpw.png" /><figcaption>Conforming the presentable to the actual viewModel to provide actual implementation.</figcaption></figure><p>ListViewModel now have flowing the viewModels wrapped inside a protocol `TaskListItemPresentable` and cells will get appropriate viewModel for further processing and ask ask the presentable for rendering data. Which ultimately will get resolved at correct ViewModel. eg. if a First title cell receive a presentable TaskNameInputPresentable and set a label title using presentable.title, ultimately a viewModel instance is providing the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VSmDQzm2LP83V2LNofLMGA.png" /><figcaption>Diagram 2</figcaption></figure><h3>Consuming Presentable Protocol in a View</h3><p>Your View layer can be anything which is a user interface. It can be an UIView, or a UITableViewCell, UICollectionViewCell etc. Let me give an example for how we can consume the above defined protocols in the view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L651Vk_i8bwbXU6VuyI6Wg.png" /><figcaption>Consuming Presentable Protocol in a View</figcaption></figure><p>If you can see from the code and also from the <em>Diagram 2</em> given above, view is actually interacting with a `CellViewModel` which is wrapped inside the presentable protocol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*fUKcmPF4cC2DGSIIfqErig.png" /><figcaption>View uses a Presentable which is actually a ViewModel wrapped in Presentable</figcaption></figure><p>Note: The ViewModels and protocols created for example purpose, there are many more advanced ways to do better for handling events, binding, updating UI reactively etc.</p><p>Really hope you like this article. Thank you for reading :)</p><p>Please feel free to reach me at <em>mohshinshah@gmail.com</em> for feedback or any suggestions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4c5b76a92e1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ne-digital/mvvm-pop-to-deal-with-complex-ui-d4c5b76a92e1">MVVM + POP to deal with complex UI</a> was originally published in <a href="https://medium.com/ne-digital">NE Digital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID: Dependency Inversion Principle(DIP)]]></title>
            <link>https://mohshinshah.medium.com/solid-dependency-inversion-principle-dip-929da9af6672?source=rss-984e4061cdfc------2</link>
            <guid isPermaLink="false">https://medium.com/p/929da9af6672</guid>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[dependency-inversion]]></category>
            <category><![CDATA[uncle-bob]]></category>
            <dc:creator><![CDATA[Mohshin Shah]]></dc:creator>
            <pubDate>Mon, 08 Feb 2021 07:30:30 GMT</pubDate>
            <atom:updated>2021-02-08T07:30:30.611Z</atom:updated>
            <content:encoded><![CDATA[<p>Robert C. Martin’s defined the of the DIP as below with two parts</p><blockquote>High-level modules should not depend on low-level modules. Both should depend on abstractions.</blockquote><blockquote>Abstractions should not depend on details. Details should depend on abstractions.</blockquote><p><strong>What is High-level and Low-level?</strong></p><p>High level meaning the business requirement and low-level means the technical details, how that is implemented. For example Payment Processing can called higher level of module and how it is done technically using Visa’s framework, Internet banking etc are the lower level details.</p><p>Here is one more example, Loading the feed depending on the Network which is a low level module and if it is to be changed then FeedLoader will break. For example for writing Unit test cases we need Mock network or use of some third party network library instead this cases will break the higher level module Feed.</p><pre>class Network {<br>    func request(_ urlRequest: URLRequest, completion: <a href="http://twitter.com/escaping">@escaping</a> (Result&lt;Data, Error&gt;) -&gt; Void) {<br>        ...<br>        URLSession.shared.request. bla bla<br>    }</pre><pre>}<br>class FeedLoader {<br>    let network: Network<br>    init(_ network: Network) {<br>        self.network = network<br>    }</pre><pre>func loadFeed(url: URLRequest, completion: <a href="http://twitter.com/escaping">@escaping</a> (Result&lt;[String], Error&gt;) -&gt; Void) {<br>        // Loading Feed using URLSession<br>        network.request<br>    }</pre><pre>}</pre><p>In the example above,</p><p>Feed Module (High Level) depending on the Low-Level Network Module. So to solve we have to introduce one layer of abstraction</p><p>to make higher level and low level implementation both depend on the interface/abstraction layer</p><p><strong>Feed Module — — — — — → Abstraction ← — — — — Network</strong></p><pre>protocol Network {<br>    func request(_ urlRequest: URLRequest, completion: <a href="http://twitter.com/escaping">@escaping</a> (Result&lt;Data, Error&gt;) -&gt; Void)<br>}</pre><pre>class URLNetwork: Network {<br>    func request(_ urlRequest: URLRequest, completion: <a href="http://twitter.com/escaping">@escaping</a> (Result&lt;Data, Error&gt;) -&gt; Void) {<br>        URLSession.shared...<br>    }</pre><pre>}</pre><pre>class AlamofireNetwork: Network {<br>    func request(_ urlRequest: URLRequest, completion: <a href="http://twitter.com/escaping">@escaping</a> (Result&lt;Data, Error&gt;) -&gt; Void) {<br>        AF.shared...<br>    }</pre><pre>}</pre><pre>class MockNetwork: Network {<br>    func request(_ urlRequest: URLRequest, completion: <a href="http://twitter.com/escaping">@escaping</a> (Result&lt;Data, Error&gt;) -&gt; Void) {<br>        let dummyDataFortesting = ....<br>        completion(.success(dummyDataFortesting))<br>    }</pre><pre>}<br>class FeedLoader {<br>    let network: Network<br>    init(_ network: Network) {<br>        self.network = network<br>    }</pre><pre>func loadFeed(url: URLRequest, completion: <a href="http://twitter.com/escaping">@escaping</a> (Result&lt;[String], Error&gt;) -&gt; Void) {<br>        // Loading Feed using URLSession<br>        network.instance.<br>    }</pre><pre>}</pre><p>Now we can test, change lower-level framework without affecting the Feed module.</p><p>As mentioned in earlier post, <strong>All SOLID principles are intertwined with each other, </strong>So If we apply OCP and LSV properly we would automatically achieve the DIP.</p><p>That’s all for this time. Thanks for reading my articles. Cheers 🍺🍺🍺</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=929da9af6672" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID: Interface Segregation Principle (ISP)]]></title>
            <link>https://mohshinshah.medium.com/solid-interface-segregation-principle-isp-db292fe0edc4?source=rss-984e4061cdfc------2</link>
            <guid isPermaLink="false">https://medium.com/p/db292fe0edc4</guid>
            <category><![CDATA[uncle-bob]]></category>
            <category><![CDATA[interface-segregation]]></category>
            <category><![CDATA[solid]]></category>
            <dc:creator><![CDATA[Mohshin Shah]]></dc:creator>
            <pubDate>Mon, 08 Feb 2021 07:30:01 GMT</pubDate>
            <atom:updated>2021-02-08T07:38:11.154Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>“No client should be forced to depend on methods it does not use.”</strong></blockquote><p><strong><em>Real World Analogy: </em></strong>Suppose, you go to a market to buy a charger for your iPhone.And you purchased a charger which has iPhone plug but also has Samsung, Nokia and Moto plugs too, which you never gonna use. That’s what an ISP solves, making sure you get an iPhone charger only.</p><p>Sometimes when we create interfaces we see the</p><ul><li>Empty implementations</li><li>Big Interface with too many methods</li><li>Methods are not relevant to each other (Low Cohesion)</li></ul><p>This all indicates the violation of ISP.</p><p>To understand this lets see an example below,</p><pre>protocol MediaPlayable {<br>    func play()<br>    func pause()<br>    func download()<br>    func seek(to time: TimeInterval)<br>    var url: URL?<br>}</pre><p>At first, glance it looks okay but when we have the implementation of this it would have the issues.</p><pre>class AudioPlayer: MediaPlayable {<br>    let player: ThirdPartyVideoPlayer?<br>    func play() { player.playAudio() }<br>    func pause() { player.pauseAudio() }<br>    func download() { // Cant }<br>    func seek(to time: TimeInterval) { player.seekAudio(to: time) }<br>}</pre><pre>class VideoPlayer: MediaPlayable {<br>    let player: VideoPlayer?<br>    func play() { player.playVideo() }<br>    func pause() { player.pauseVideo() }<br>    func download() { // Cant }<br>    func seek(to time: TimeInterval) { player.seekVideo(to: time) }<br>}</pre><pre>class NetFlixPlayer: MediaPlayable {<br>    let player: NFPlayer?<br>    func play() { player.play() }<br>    func pause() { player.pause() }<br>    func download() { player.saveToGallery() }<br>    func seek(to time: TimeInterval) { player.saveToGallery() }<br>}</pre><pre>class TVPlayer: MediaPlayable {<br>    let player: RemoteTVPlayer?<br>    func play() { player.playTVStation() }<br>    func pause() { player.stop() }<br>    func download() { // Cant }<br>    func seek(to time: TimeInterval) { // Cant }<br>}</pre><p>Woaha ! so many empty methods, Meaning there is some issue at the abstraction layer.</p><p>Plus If download is called on AudioPlayer instance would not work same as the contract, breaking the <strong>LSV</strong> rule.</p><p>We can easily solve this by breaking or decomposing the MediaPlayable as below and make high cohesive small interfaces.</p><pre>protocol Playable {<br>    func play()<br>    func pause()<br>}</pre><pre>protocol Seekable {<br>    func seek(to time: TimeInterval)<br>}</pre><pre>protocol Downloadable {<br>    func download()<br>}</pre><pre>class AudioPlayer: Playable, Seekable {<br>    let player: ThirdPartyVideoPlayer?<br>    func play() { player.playAudio() }<br>    func pause() { player.pauseAudio() }<br>    func seek(to time: TimeInterval) { player.seekAudio(to: time) }<br>}</pre><pre>class VideoPlayer: Playable, Seekable {<br>    let player: VideoPlayer?<br>    func play() { player.playVideo() }<br>    func pause() { player.pauseVideo() }<br>    func seek(to time: TimeInterval) { player.seekVideo(to: time) }<br>}</pre><pre>class NetflixPlayer: Playable, Seekable, Downloadable {<br>    let player: NFPlayer?<br>    func play() { player.play() }<br>    func pause() { player.pause() }<br>    func download() { player.saveToGallery() }<br>    func seek(to time: TimeInterval) { player.saveToGallery() }<br>}</pre><pre>class TVPlayer: Playable {<br>    let player: RemoteTVPlayer?<br>    func play() { player.playTVStation() }<br>    func pause() { player.stop() }<br>}</pre><p><em>Fat protocols sound like “Too many responsibilities” for an interface (SRP) <br>&amp; no empty implementations meaning more likely to break LSV violation.</em></p><h3>Yes, all SOLID principles are intertwined with each other.</h3><p>Lets move to our last rule <a href="https://medium.com/@mohshinshah/solid-dependency-inversion-principle-dip-929da9af6672"><strong>Dependency Inversion Principle</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db292fe0edc4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID: Liskov Substitution Principle(LSP)]]></title>
            <link>https://mohshinshah.medium.com/solid-liskov-substitution-principle-lsp-9e75d7a3f767?source=rss-984e4061cdfc------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e75d7a3f767</guid>
            <dc:creator><![CDATA[Mohshin Shah]]></dc:creator>
            <pubDate>Mon, 08 Feb 2021 07:29:37 GMT</pubDate>
            <atom:updated>2021-02-08T07:36:59.763Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>LSV is actually an extension to OCP.<br></strong>Meaning, it helps to correct your OCP implementation correct way.</p><blockquote>If S is a subtype of T, then objects of type T may be replaced with objects of type S, without breaking the program</blockquote><p><strong>Inheritance</strong>:<br>Objects of a super class should be replaceable with the object of Sub Classes</p><p>Let understand this with a violation</p><pre>class DeliveryProvider {<br>    func deliver(to address: String) {<br>        print(&quot;Package delviered to: \(address)&quot;)<br>    }</pre><pre>}<br>class ExpressDeliveryProvider {<br>    override func deliver(to address: String) {<br>        print(&quot;Package received, Press 1 key to proceed&quot;)<br>        // Wait for the user input<br>        waitForUserInput() {<br>            input in<br>            if input = 1 {<br>                print(&quot;Package delviered to: \(address)&quot;)<br>            }<br>        }<br>    }</pre><pre>}<br>let objectOfSuperType = DeliveryProvider()<br>let objectOfSubType = ExpressDeliveryProvider()<br>objectOfSuperType.deliver(to: &quot;Singpoare 11&quot;)<br>objectOfSubType.deliver(to: &quot;Singpoare 11&quot;) // Can not replace the Super Class object with subtype means there is some design issue</pre><p>See Here, Can not replace the Super Class object with subtype means there is some design issue</p><pre><strong>objectOfSuperType.deliver(to: “Singpoare 11”)<br>objectOfSubType.deliver(to: “Singpoare 11”)</strong></pre><p>Because, <strong>SUB</strong> <strong>CLASS</strong> not behaving the same way as <strong>SUPER CLASS</strong>. It is not delivering the package directly. It is awaiting user’s input to proceed.</p><p><strong>Interface/Protocol:<br></strong>Two implementation of the same interface or protocol can be used interchangeably without unexpected behaviour.</p><p>Let’s see an example,<br>There is a web service interface which can be used in the application and also for the unit tests. But in unit tests the <strong>FeedService</strong> would be mock.</p><pre>protocol FeedWebService {<br>    // Gets all the feed items and return completion on main thread.<br>    func get(_ urlRequest: URLRequest, completion: <a href="http://twitter.com/escaping">@escaping</a> ([Feed]?, Error?) -&gt; Void)<br>}</pre><p>Feed Screen which lists all the feeds using the feed service injected into it.</p><pre>class FeedScreen {<br>    let ws: FeedWebService<br>    init(webservice: FeedWebService) {<br>        self.ws = webService<br>    }</pre><pre>func getAllFeedItems() {<br>        let request = URLRequest..... // URL request to get feed items<br>        ws.get(request) {<br>            feedItems, error in<br>            // got response or error<br>            // Update UI accordinglt<br>            // like  tableView.reload etc<br>        }<br>    }</pre><pre>}</pre><p>Now let’s see how the FeedService can be implemented for real network and mock network and understand what is the violation and how to fix it.</p><pre>class URLNetwork: FeedWebservice {<br>    func get(_ urlRequest: URLRequest, completion: <a href="http://twitter.com/escaping">@escaping</a> ([Feed]?, Error?) -&gt; Void) {<br>        let task = URLSession.shared.dataTask(with: urlRequest.url) {<br>            data, response, error in<br>            if let error = error {<br>                DispatchQueue.main.async {<br>                    completion(nil, error)<br>                }<br>                completion(nil, error)<br>                return<br>            }<br>            //. else decode Feed from data and send in completion<br>            //. let feedArray = JSONDecoder().decode...<br>            DispatchQueue.main.async {<br>                completion(feedArray, nil)<br>            }<br>        }<br>    }</pre><p>Mock Implementation for the Unit Test</p><pre>class MockNetwork: FeedWebService {<br>    func get(_ urlRequest: URLRequest, completion: <a href="http://twitter.com/escaping">@escaping</a> ([Feed]?, Error?) -&gt; Void) {<br>        let feedArray = [Feed(), Feed()]<br>        DispatchQueue.global(qos: .background).async {<br>            completion(feedArray, nil)<br>        }<br>    }</pre><pre>}</pre><h3>So far what we have done is nothing but the OCP, but how to make sure that our OCP is correct or not. <em>Tada</em>, here comes the LSP.</h3><pre>let webService = URLNetwork()<br><strong>// let mockWebService = MockNetwork()</strong></pre><pre>let feedScreen = FeedScreen(webService: webService)<br>feedScreen.getAllFeedItems()</pre><p>Here <strong>URLNetwork</strong> and <strong>MockNetwork</strong> are the implementations for the protocol/interface <strong>FeedWebService</strong></p><p>But for <strong>MockNetwork</strong>, it is not returning the completion on main thread which we expect as per protocol design<br><em>(This is also called the </em><strong><em>Design By Contract</em></strong><em> or </em><strong><em>Design by protocol</em></strong><em> violation).</em></p><p>Therefore we would <strong>not</strong> be able to swap this two implementation without changing the code which is <strong>LSP violation <br></strong>If we try to swap webService with mockWebService , it would break the UI operations which expecting main thread.</p><p>Read the definition again and it would be more clear after this example, Try!</p><p>So to solve this we can make the <strong>MockNetwork</strong> ‘s implementation to return on main thread only to avoid unexpected behaviour and follow LSP.</p><p><em>See, how LSV allows you to make sure that your OCP is done properly.</em></p><p>Lets move to the next topic <a href="https://mohshinshah.medium.com/solid-interface-segregation-principle-isp-db292fe0edc4">Interface Segregation Principle</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e75d7a3f767" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>