<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Haris Madhavan</title>
    <description>The latest articles on DEV Community by Haris Madhavan (@harismadhavan).</description>
    <link>https://dev.to/harismadhavan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2573550%2F446c7d69-7b35-4cde-9dc9-964d3a677f45.jpeg</url>
      <title>DEV Community: Haris Madhavan</title>
      <link>https://dev.to/harismadhavan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/harismadhavan"/>
    <language>en</language>
    <item>
      <title>Access Control Levels in Swift</title>
      <dc:creator>Haris Madhavan</dc:creator>
      <pubDate>Tue, 24 Dec 2024 13:26:02 +0000</pubDate>
      <link>https://dev.to/harismadhavan/access-control-levels-in-swift-4lmo</link>
      <guid>https://dev.to/harismadhavan/access-control-levels-in-swift-4lmo</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp0qoih62i1vl8dafpo2b.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp0qoih62i1vl8dafpo2b.jpg" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Access control levels in Swift determine the scope and visibility of classes, structures, functions, properties, and other entities in your code. They define who can access or modify a particular piece of code, helping you manage code organization, security, and modularity.&lt;/p&gt;




&lt;h3&gt;
  
  
  Access Control Levels in Swift
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Open&lt;/strong&gt; (Most Permissive)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scope:&lt;/strong&gt; Available to any module or file, including subclasses outside the module.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage:&lt;/strong&gt; Used for public APIs or frameworks where entities must be subclassable and overridden outside the module.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;open class OpenClass {
    open func greet() {
        print("Hello!")
    }
}

class Subclass: OpenClass {
    override func greet() {
        print("Hi!")
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows &lt;strong&gt;&lt;em&gt;OpenClass&lt;/em&gt;&lt;/strong&gt; and its &lt;strong&gt;&lt;em&gt;greet()&lt;/em&gt;&lt;/strong&gt; method to be subclassed and overridden in other modules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Public&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scope:&lt;/strong&gt; Accessible in any module but not subclassable or overridable outside the module.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage:&lt;/strong&gt; Used for exposing interfaces or functionality to other modules without subclassing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class PublicClass {
    public func greet() {
        print("Hello!")
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Internal&lt;/strong&gt; (Default)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scope:&lt;/strong&gt; Accessible only within the same module (e.g., app target or framework).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage:&lt;/strong&gt; The default access level for most entities unless explicitly specified.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class InternalClass {
    func greet() {
        print("Hello!")
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Fileprivate&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scope:&lt;/strong&gt; Accessible only within the same source file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage:&lt;/strong&gt; Used when you want to restrict access to helper methods or properties within a single file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fileprivate class FileprivateClass {
    fileprivate func greet() {
        print("Hello!")
    }
}

class AnotherClassInSameFile {
    func sayHi() {
        let instance = FileprivateClass()
        instance.greet()
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Private&lt;/strong&gt; (Most Restrictive)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scope:&lt;/strong&gt; Accessible only within the same enclosing declaration (e.g., class, struct).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage:&lt;/strong&gt; Used to encapsulate implementation details and restrict access within a specific declaration.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class PrivateClass {
    private var secretMessage = "Hidden!"

    private func showSecret() {
        print(secretMessage)
    }

    func revealSecret() {
        showSecret() // Accessible within the same class.
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Why Are Access Control Levels Useful?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Encapsulation:&lt;/strong&gt;&lt;br&gt;
Access control enforces the principle of hiding implementation details, exposing only what is necessary for use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Modularity:&lt;/strong&gt;&lt;br&gt;
Helps in creating modular and reusable code by defining clear boundaries for access.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security:&lt;/strong&gt;&lt;br&gt;
Restricts access to sensitive data or critical code sections to prevent misuse or unintended modifications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API Design:&lt;/strong&gt;&lt;br&gt;
Public or open access levels allow you to define APIs for other developers while keeping the implementation private or internal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Maintenance:&lt;/strong&gt;&lt;br&gt;
Prevents accidental access or modifications to parts of code that are not meant to be externally visible.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Choosing the Right Access Level
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;&lt;em&gt;private&lt;/em&gt;&lt;/strong&gt; for implementation details you don’t want accessed outside a class/struct.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;&lt;em&gt;fileprivate&lt;/em&gt;&lt;/strong&gt; sparingly, typically for testing or tightly related logic.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;&lt;em&gt;internal&lt;/em&gt;&lt;/strong&gt; by default for most app logic.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;&lt;em&gt;public&lt;/em&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;em&gt;open&lt;/em&gt;&lt;/strong&gt; only for entities that need external visibility, such as APIs or framework components.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Understanding and using access control effectively helps build secure, modular, and maintainable Swift applications.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
    </item>
    <item>
      <title>MVC vs MVVM: A Real-Life iOS Interview Insight</title>
      <dc:creator>Haris Madhavan</dc:creator>
      <pubDate>Mon, 23 Dec 2024 01:41:24 +0000</pubDate>
      <link>https://dev.to/harismadhavan/mvc-vs-mvvm-a-real-life-ios-interview-insight-1h0d</link>
      <guid>https://dev.to/harismadhavan/mvc-vs-mvvm-a-real-life-ios-interview-insight-1h0d</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe6syb7aen0denj1glmel.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe6syb7aen0denj1glmel.jpg" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
In a recent interview for an iOS Developer position, I encountered an interesting question that tested my knowledge of design patterns and my understanding of how they evolve. The discussion revolved around MVC and MVVM, two fundamental design patterns in iOS development. While I was prepared to explain their basics, the interviewer’s follow-up question surprised me.&lt;/p&gt;

&lt;p&gt;In this article, I’ll share the question, my initial response, and what I learned from the experience. If you’re preparing for iOS interviews, this might help you navigate similar situations!&lt;/p&gt;




&lt;h3&gt;
  
  
  The Question: “How Does the Controller Fit into MVVM?”
&lt;/h3&gt;

&lt;p&gt;The interview started with a familiar question:&lt;br&gt;
&lt;strong&gt;“Can you explain the difference between MVC and MVVM?”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I confidently answered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MVC&lt;/strong&gt; stands for &lt;strong&gt;Model-View-Controller&lt;/strong&gt;, where the Controller handles user input and updates the View and Model accordingly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MVVM&lt;/strong&gt; stands for &lt;strong&gt;Model-View-ViewModel&lt;/strong&gt;, where business logic is separated from the View and placed in the ViewModel.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Feeling good about my response, I didn’t expect the next question:&lt;br&gt;
&lt;strong&gt;“In MVVM, there’s no ‘Controller.’ So, where does the Controller’s role go?”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I was stumped. I hadn’t thought about this distinction in depth before. After the interview, I took some time to reflect and understand the concept better.&lt;/p&gt;




&lt;h3&gt;
  
  
  Understanding MVC and MVVM:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;MVC (Model-View-Controller):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;Model&lt;/strong&gt; represents the data and business logic.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;View&lt;/strong&gt; displays the data to the user.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Controller&lt;/strong&gt; acts as a bridge between the Model and View, handling user inputs and updating the data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this pattern, the Controller often takes on a lot of responsibility, making it prone to becoming &lt;strong&gt;“massive”&lt;/strong&gt; (the infamous &lt;strong&gt;Massive View Controller&lt;/strong&gt; problem).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MVVM (Model-View-ViewModel):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;Model&lt;/strong&gt; remains the same.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;View&lt;/strong&gt; still handles the UI.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;ViewModel&lt;/strong&gt; introduces a layer that manages the business logic and data-binding to the View.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In &lt;strong&gt;MVVM&lt;/strong&gt;, there’s no explicit &lt;strong&gt;Controller&lt;/strong&gt;. Instead, its responsibilities are split between the &lt;strong&gt;View&lt;/strong&gt;(handling user inputs) and the &lt;strong&gt;ViewModel&lt;/strong&gt; (handling logic and data).&lt;/p&gt;




&lt;h3&gt;
  
  
  Where the Controller’s Role Goes in MVVM:
&lt;/h3&gt;

&lt;p&gt;In &lt;strong&gt;UIKit-based MVVM&lt;/strong&gt; apps, the ViewController still exists but acts purely as part of the View. It:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handles UI setup and user input.&lt;/li&gt;
&lt;li&gt;Binds the UI to the ViewModel.&lt;/li&gt;
&lt;li&gt;Forwards actions to the ViewModel.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In &lt;strong&gt;SwiftUI&lt;/strong&gt;, the View directly binds to the ViewModel, eliminating the need for a separate ViewController altogether.&lt;/p&gt;




&lt;h3&gt;
  
  
  My Takeaways:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Design Patterns Evolve:&lt;/strong&gt;&lt;br&gt;
It’s important to understand not just the structure but also the responsibilities of each component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Be Prepared for Deeper Questions:&lt;/strong&gt;&lt;br&gt;
Interviewers often go beyond surface-level questions to test your understanding of concepts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reflection is Key:&lt;/strong&gt;&lt;br&gt;
While I didn’t have a perfect answer in the moment, reflecting on the question helped me solidify my understanding for the future.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;If you’re preparing for iOS interviews, take some time to deeply understand how design patterns distribute responsibilities. MVC and MVVM are more than just acronyms — they represent different philosophies in organizing code.&lt;/p&gt;

&lt;p&gt;I hope this insight helps you in your interview journey. Have you faced similar questions? I’d love to hear about your experiences!&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
    </item>
  </channel>
</rss>
