<?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 Nayana N P on Medium]]></title>
        <description><![CDATA[Stories by Nayana N P on Medium]]></description>
        <link>https://medium.com/@nayananp?source=rss-cce136e72001------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*53DsYJBzchtP0LgN8UNyTA.png</url>
            <title>Stories by Nayana N P on Medium</title>
            <link>https://medium.com/@nayananp?source=rss-cce136e72001------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 14:12:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nayananp/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[ Cracking the Code: Grouping Anagrams in Swift]]></title>
            <link>https://medium.com/@nayananp/cracking-the-code-grouping-anagrams-in-swift-4091863b6541?source=rss-cce136e72001------2</link>
            <guid isPermaLink="false">https://medium.com/p/4091863b6541</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[pair-programming]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[iphone]]></category>
            <dc:creator><![CDATA[Nayana N P]]></dc:creator>
            <pubDate>Thu, 30 Apr 2026 14:45:18 GMT</pubDate>
            <atom:updated>2026-04-30T14:45:18.149Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wGzoshL2LZBEb0XAikBYRQ.png" /><figcaption>Anagram Groups</figcaption></figure><h4>✨ The Problem</h4><p>You’ve probably seen this one pop up during coding interviews or while practicing on LeetCode:<br><strong>“Group words that are anagrams of each other.”</strong></p><p>Sounds simple, right? But solving it cleanly and efficiently is where it gets interesting — especially when you’re working in <strong>Swift</strong>.</p><p>Let’s dive into an intuitive way to tackle this problem.</p><h4>🎯 What Are Anagrams?</h4><p>Anagrams are words formed by rearranging the letters of another word.</p><p><strong>Example:</strong></p><ul><li>“eat”, “tea”, and “ate” are all anagrams.</li><li>“bat” is not an anagram of any of them.</li></ul><p>So, given an array of strings, we want to <strong>group all anagrams together</strong> and return <strong>the number of such groups</strong>.</p><h4>💻 The Swift Code</h4><p>Here’s the Swift solution:</p><pre>// group anagrams<br>func groupAnagrams(words: [String]) -&gt; Int {<br>    <br>    var anagramGroup = [String: [String]]()<br>    <br>    for word in words {<br>        let sortedWord = String(word.sorted())<br>        print(sortedWord) // Optional: for debug<br>        anagramGroup[sortedWord, default: []].append(word)<br>    }<br>    <br>    print(anagramGroup)<br>    return anagramGroup.count<br>}<br><br>print(groupAnagrams(words: [&quot;eat&quot;, &quot;tea&quot;, &quot;tan&quot;, &quot;ate&quot;, &quot;nat&quot;, &quot;bat&quot;]))</pre><h4>🧠 How It Works</h4><p>Let’s break it down:</p><ol><li><strong>Sort Each Word</strong></li></ol><ul><li>Sorting the letters of each word gives a canonical form.</li><li>“tea” → “aet”</li><li>“eat” → “aet”</li><li>“bat” → “abt”</li></ul><p><strong>2. Use a Dictionary</strong></p><ul><li>Keys are sorted words.</li><li>Values are arrays of the original words that share the same letters.</li></ul><p><strong>3. Group and Count</strong></p><ul><li>All words that become the same after sorting are grouped together.</li><li>Return the count of these unique sorted keys.</li></ul><h4>📦 Sample Output</h4><p>Given this input:</p><pre>[&quot;eat&quot;, &quot;tea&quot;, &quot;tan&quot;, &quot;ate&quot;, &quot;nat&quot;, &quot;bat&quot;]</pre><p>The debug output might look like this:</p><pre>aet<br>aet<br>ant<br>aet<br>ant<br>abt<br>[&quot;aet&quot;: [&quot;eat&quot;, &quot;tea&quot;, &quot;ate&quot;], <br> &quot;ant&quot;: [&quot;tan&quot;, &quot;nat&quot;], <br> &quot;abt&quot;: [&quot;bat&quot;]]<br><br><br>Result: <br><br>3 // Because we have 3 anagram groups.</pre><h4>🛠 Why This Is Elegant</h4><ul><li><strong>Scalability</strong>: Works well with large lists.</li><li><strong>Simplicity</strong>: Easy to read and reason about.</li><li><strong>Performance</strong>: Dictionary lookup and sorting (which is cheap for short strings) make it efficient.</li></ul><h4>🧩 Wrap-Up</h4><p>Whether you’re building a word game, filtering search suggestions, or preparing for your next Swift interview, knowing how to group anagrams effectively is a great trick to keep in your back pocket.</p><p>Got an even cleaner approach? Add a twist to the algorithm? Share your version in the comments or fork it and tag me!</p><p>✍️ <em>Nayana N P </em><br>📬 <em>Follow me for more Swift deep dives, coding tips, and clean code write-ups!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4091863b6541" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Building a Simple UIKit Notes App with Validation, Unit Tests & UI Testing]]></title>
            <link>https://medium.com/@nayananp/building-a-simple-uikit-notes-app-with-validation-unit-tests-ui-testing-a3b616e1ead8?source=rss-cce136e72001------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3b616e1ead8</guid>
            <dc:creator><![CDATA[Nayana N P]]></dc:creator>
            <pubDate>Thu, 30 Apr 2026 14:43:58 GMT</pubDate>
            <atom:updated>2026-04-30T14:43:58.144Z</atom:updated>
            <content:encoded><![CDATA[<p>When preparing for a pair programming iOS interview, it’s common to be given vague requirements like:</p><ul><li>“Make a notes app.”</li><li>“Handle empty fields and date validations.”</li><li>“Use UIKit, not SwiftUI.”</li><li>“Just assume what’s needed.”</li></ul><p>Here’s how I turned this ambiguity into a concrete, testable, and interview-ready iOS UIKit project — while following best practices like testability, validation, and UIKit fundamentals.</p><h3>🚧 The Problem</h3><p>I needed to build a basic Notes app where users can:</p><ul><li>Add a note with a title and due date.</li><li>Save the note only if the title is not empty.</li><li>Prevent saving if the selected date is in the past.</li><li>Notify users using UIAlertController.</li><li>Make sure the code is <strong>testable</strong> and includes <strong>unit tests</strong> and <strong>UI tests</strong>.</li></ul><h3>🧱 Step 1: Building the UI in UIKit (Programmatically)</h3><p>To avoid storyboard confusion and maximize flexibility, I built the UI programmatically using UITextField, UIDatePicker, and UIButton.</p><pre>titleTextField.placeholder = &quot;Enter title&quot;<br>datePicker.minimumDate = Date()</pre><h3>✅ Step 2: Validating Notes</h3><p>Instead of cluttering the view controller, I created a dedicated NoteValidator class:</p><pre>class NoteValidator {<br>    func validate(note: Note) -&gt; ValidationResult {<br>        if note.title.trimmingCharacters(in: .whitespaces).isEmpty {<br>            return .failure(&quot;Title can&#39;t be empty.&quot;)<br>        }<br>        if note.dueDate &lt; Date() {<br>            return .failure(&quot;Date cannot be in the past.&quot;)<br>        }<br>        return .success<br>    }<br>}</pre><h3>🧪 Step 3: Unit Testing with XCTest</h3><p>I added tests to check:</p><ul><li>Fails if title is empty.</li><li>Fails if date is in the past.</li><li>Succeeds if both are valid.</li></ul><pre>func testEmptyTitleShouldFail() { ... }<br>func testPastDateShouldFail() { ... }</pre><p>Tests were simple but essential for confidence and correctness.</p><h3>🤖 Step 4: UI Testing with XCUITest</h3><p>I added UI tests to simulate real-world user interaction:</p><ul><li>Leave title blank → show error</li><li>Pick past date → show error</li><li>Enter valid note → show success</li></ul><pre>let titleField = app.textFields[&quot;Enter title&quot;]<br>titleField.tap()<br>titleField.typeText(&quot;Test Note&quot;)</pre><p>Tip: I used accessibilityIdentifier to help UI tests find views reliably.</p><h3>⚡ What This Demonstrated to Interviewers</h3><ul><li><strong>Validation logic</strong> extracted cleanly for reuse and testing.</li><li><strong>UIKit fundamentals</strong> — views, actions, layout, alerts.</li><li><strong>Test-driven thinking</strong> — unit + UI testing.</li><li><strong>Handling ambiguity</strong> with sensible assumptions.</li><li><strong>Debugging tools</strong>: breakpoints + po in console when needed.</li></ul><h3>🧩 What I Would Add Next</h3><ul><li>Store notes using CoreData or UserDefaults.</li><li>List notes in a UITableView.</li><li>Edit/delete support.</li><li>ViewModel layer for separation of concerns.</li></ul><h3>📌 Final Thoughts</h3><p>This small UIKit Notes App covered a surprising amount of ground:</p><ul><li>Clean code.</li><li>MVC.</li><li>Error handling.</li><li>Testability.</li><li>UIKit layout without Storyboards.</li></ul><p>It’s a great base for pair programming or take-home challenges where clarity and structure matter more than complexity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3b616e1ead8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Configure SourceTree to Use Your GitHub SSH Key on macOS]]></title>
            <link>https://medium.com/@nayananp/how-to-configure-sourcetree-to-use-your-github-ssh-key-on-macos-94d84e89cd45?source=rss-cce136e72001------2</link>
            <guid isPermaLink="false">https://medium.com/p/94d84e89cd45</guid>
            <dc:creator><![CDATA[Nayana N P]]></dc:creator>
            <pubDate>Mon, 19 Jan 2026 13:00:26 GMT</pubDate>
            <atom:updated>2026-01-19T13:00:26.754Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dYKy3FjlOnTG3BPVypHbtA.png" /></figure><p>For adding new SSH key to GitHub refer: <a href="https://medium.com/@nayananp/generate-a-new-ssh-key-and-add-it-to-github-from-macos-5609dc4b308d">https://medium.com/@nayananp/generate-a-new-ssh-key-and-add-it-to-github-from-macos-5609dc4b308d</a></p><p>After generating an SSH key and adding it to GitHub, many developers expect everything to “just work.” But if you’re using <strong>SourceTree on macOS</strong>, you might still run into errors like <strong>“Repository not found”</strong> or repeated authentication prompts.</p><p>The reason? SourceTree doesn’t always use your system SSH configuration by default.</p><p>In this guide, I’ll show you <strong>how to configure SourceTree to use the same SSH key you added to GitHub</strong>, step by step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7SNbEahFcTi1kPc37SekHA.png" /></figure><h3>Why SourceTree Needs Extra Configuration</h3><p>On macOS, SourceTree can use:</p><ul><li>its <strong>bundled Git</strong>, or</li><li>your <strong>system Git</strong></li></ul><p>Only <strong>System Git + OpenSSH</strong> reliably respects:</p><ul><li>~/.ssh/id_ed25519</li><li>ssh-agent</li><li>macOS Keychain</li><li>SSO-authorized SSH keys</li></ul><p>So the goal is simple: <strong>force SourceTree to use the system setup</strong>.</p><h3>1. Configure SourceTree to Use System Git</h3><ol><li>Open <strong>SourceTree</strong></li><li>Go to <strong>SourceTree → Settings (Preferences)</strong></li><li>Open the <strong>Git</strong> tab</li><li>Set <strong>Git version</strong> to <strong>System Git</strong></li></ol><p>If macOS prompts you to install Command Line Tools, allow it.</p><p>💡 This ensures SourceTree uses the same Git you use in Terminal.</p><h3>2. Configure SourceTree to Use OpenSSH</h3><p>In <strong>Settings</strong>, go to the <strong>SSH</strong> tab:</p><ul><li><strong>SSH client configuration</strong> → <strong>OpenSSH</strong></li><li>Leave the SSH key field <strong>empty</strong></li></ul><p>Why leave it empty?</p><p>Because OpenSSH automatically picks up your key from:</p><pre>~/.ssh/id_ed25519</pre><h3>3. Restart SourceTree (🚨Important)</h3><p>SourceTree caches Git and SSH settings.</p><ul><li>Quit SourceTree completely</li><li>Reopen it</li></ul><p>Skipping this step can make it seem like nothing changed.</p><h3>4. Ensure Your Repository Uses SSH</h3><p>In SourceTree:</p><ol><li>Open the repository</li><li>Go to <strong>Repository Settings → Remotes</strong></li><li>Ensure the remote URL looks like:</li></ol><pre>git@github.com:&lt;org&gt;/&lt;repo&gt;.git</pre><p>If it’s HTTPS, edit the remote and switch it to SSH.</p><h3>5. Test SSH From SourceTree</h3><p>From SourceTree:</p><ul><li>Click <strong>Repository → Open in Terminal</strong></li><li>Run:</li></ul><pre>ssh -T git@github.com</pre><p>If you see:</p><pre>Hi &lt;username&gt;! You&#39;ve successfully authenticated…</pre><p>Then SourceTree is correctly using your SSH key.</p><h3>6. Load the SSH Key (If Needed)</h3><p>If SourceTree still fails to push or pull, your SSH key may not be loaded.</p><p>Run in Terminal:</p><pre>ssh-add ~/.ssh/id_ed25519</pre><p>verify:</p><pre>ssh-add -l</pre><h3>7. (Recommended) Add an SSH Config File</h3><p>Create or edit ~/.ssh/config:</p><pre>nano ~/.ssh/config</pre><p>Add:</p><pre>Host github.com<br>  HostName github.com<br>  User git<br>  IdentityFile ~/.ssh/id_ed25519<br>  AddKeysToAgent yes<br>  UseKeychain yes</pre><p>This ensures SourceTree, Terminal, and GitHub all behave consistently.</p><h3>Common Mistakes to Avoid</h3><ul><li>❌ Using SourceTree’s bundled Git</li><li>❌ Selecting PuTTY/Pageant on macOS</li><li>❌ Using HTTPS remotes with SSH keys</li><li>❌ Forgetting to authorize the SSH key for SSO</li></ul><h3>Final Thoughts</h3><p>Once SourceTree is configured to use <strong>System Git + OpenSSH</strong>, it behaves exactly like your Terminal:</p><ul><li>No passwords</li><li>No token prompts</li><li>No “Repository not found” errors</li></ul><p>If Git works in Terminal, it will work in SourceTree too.</p><p>Happy coding 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94d84e89cd45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate a New SSH Key and Add It to GitHub from macOS]]></title>
            <link>https://medium.com/@nayananp/generate-a-new-ssh-key-and-add-it-to-github-from-macos-5609dc4b308d?source=rss-cce136e72001------2</link>
            <guid isPermaLink="false">https://medium.com/p/5609dc4b308d</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[sourcetree]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[ssh-keys]]></category>
            <category><![CDATA[iphone-app-development]]></category>
            <dc:creator><![CDATA[Nayana N P]]></dc:creator>
            <pubDate>Mon, 19 Jan 2026 12:50:49 GMT</pubDate>
            <atom:updated>2026-01-19T12:50:49.970Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wl9jCLeQVze2nKmO7TK6VA.png" /></figure><p>If you’ve ever seen errors like <strong>“Repository not found”</strong> or been stuck authenticating with GitHub again and again, chances are your SSH setup needs a refresh. This is especially common after changing machines, reinstalling macOS, or enabling SSO for work organizations.</p><p>In this post, I’ll walk you through <strong>generating a new SSH key on macOS and adding it to GitHub</strong>, the right way.</p><h3>Why SSH Keys Matter</h3><p>SSH keys let you authenticate with GitHub <strong>securely and seamlessly</strong>, without typing your username and password every time you push or pull code. Once set up, Git operations just work.</p><p>GitHub recommends using <strong>ed25519</strong> keys — they’re faster, more secure, and the modern default.</p><h3>1. Generate a New SSH Key on macOS</h3><p>Open <strong>Terminal</strong> and run:</p><pre>ssh-keygen -t ed25519 -C &quot;your_email@example.com&quot;</pre><p>When prompted:</p><ul><li><strong>File location</strong> → press <strong>Enter</strong> to accept the default</li><li>(~/.ssh/id_ed25519)</li><li><strong>Passphrase</strong> → optional but recommended for extra security</li></ul><p>Once done, you’ll see a message confirming that your key pair has been created.</p><h3>Step 2: Start the SSH Agent and Add the Key</h3><p>The SSH agent manages your keys in the background.</p><p>Run:</p><pre>eval &quot;$(ssh-agent -s)&quot;<br>ssh-add ~/.ssh/id_ed25519</pre><p>Verify the key is loaded:</p><pre>ssh-add -l</pre><p>You should see your new ed25519 key listed.</p><h3>3. Copy the Public Key to Clipboard</h3><p>On macOS, this is easy:</p><pre>pbcopy &lt; ~/.ssh/id_ed25519.pub</pre><p>This copies your <strong>public key</strong> (safe to share) to your clipboard.</p><h3>4. Add the SSH Key to GitHub</h3><ol><li>Go to <strong>GitHub → Settings</strong></li><li>Click <strong>SSH and GPG keys</strong></li><li>Click <strong>New SSH key</strong></li><li>Add a descriptive title (for example: <em>MacBook Pro — Work</em>)</li><li>Paste the key</li><li>Click <strong>Add SSH key</strong></li></ol><p>Your key is now registered with GitHub.</p><h3>5. Authorize the Key for SSO (Important 🚨)</h3><p>If your GitHub organization uses <strong>SSO (SAML)</strong>, this step is mandatory.</p><ol><li>Go to <strong>GitHub → Settings → Organizations</strong></li><li>Select your organization</li><li>Navigate to <strong>Security / Authentication security</strong></li><li>Find your SSH key and click <strong>Authorize</strong></li></ol><p>Without this step, GitHub may still return <strong>“Repository not found”</strong> even though the key exists.</p><h3>6. Test the Connection</h3><p>Back in Terminal, test your setup:</p><pre>ssh -T git@github.com</pre><p>If everything is correct, you’ll see:</p><pre>Hi &lt;username&gt;! You&#39;ve successfully authenticated, but GitHub does not provide shell access.</pre><p>That’s success 🎉</p><h3>Step 7: Ensure Your Repository Uses SSH</h3><p>Check your remote URL:</p><pre>git remote -v</pre><p>If it shows HTTPS, switch to SSH:</p><pre>git remote set-url origin git@github.com:&lt;org&gt;/&lt;repo&gt;.git</pre><p>Now try:</p><pre>git pull<br>git push</pre><p>No passwords. No errors. Just code.</p><h3>Final Thoughts</h3><p>Setting up SSH keys correctly on macOS saves time, avoids authentication issues, and is essential for working with private or SSO-protected repositories.</p><p>Once done, GitHub access becomes invisible — the way it should be.</p><p>Happy coding 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5609dc4b308d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Finding the First Non-Repeating Character in Swift]]></title>
            <link>https://medium.com/@nayananp/finding-the-first-non-repeating-character-in-swift-b2e6b173e257?source=rss-cce136e72001------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2e6b173e257</guid>
            <category><![CDATA[iphone-app-development]]></category>
            <category><![CDATA[ios-interview-question]]></category>
            <category><![CDATA[ios-interview]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Nayana N P]]></dc:creator>
            <pubDate>Thu, 31 Jul 2025 12:25:26 GMT</pubDate>
            <atom:updated>2025-07-31T12:25:26.551Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AKub4_Z9og68xGIDLGLoZQ.png" /></figure><p>When working with strings in any programming language, it’s common to come across problems that require analyzing individual characters. One such classic problem is:</p><blockquote><strong><em>“Given a string, find the first character that doesn’t repeat.”</em></strong></blockquote><p>This is a great interview question and also a fun one to solve, especially in Swift. Here’s a clean, readable, and efficient implementation using dictionaries.</p><h4>🔍 The Problem</h4><p>Let’s say you have a string like &quot;swiss&quot;. You want to find the first character that doesn’t repeat. In this case, that would be &#39;w&#39;.</p><h4>🧑‍💻 The Swift Solution</h4><pre>// Find first non-repeating character<br>func firstNonRepeatingCharecter(_ value: String) -&gt; Character? {<br>    <br>    var charCount = [Character: Int]()<br>    <br>    for char in value {<br>        charCount[char, default: 0] += 1<br>    }<br>    <br>    for char in value {<br>        if charCount[char] == 1 {<br>            return char<br>        }<br>    }<br>    return nil<br>}</pre><h4>🧩 How It Works</h4><p>Let’s break it down:</p><h4>1. Count the Characters</h4><pre>for char in value {<br>    charCount[char, default: 0] += 1<br>}</pre><p>This loop builds a dictionary that keeps track of how many times each character appears.</p><h4>2. Find the First Unique One</h4><pre>for char in value {<br>    if charCount[char] == 1 {<br>        return char<br>    }<br>}</pre><p>We loop through the string again in the same order and return the first character whose count is 1.</p><h4>3. Fallback</h4><pre>return nil</pre><p>If all characters are repeating, we simply return nil.</p><h4>📈 Time &amp; Space Complexity</h4><ul><li><strong>Time Complexity:</strong> O(n)</li><li>One pass to count characters</li><li>One pass to find the first unique character</li><li><strong>Space Complexity:</strong> O(1)</li><li>Since the character set is limited (usually 128 or 256), the dictionary uses constant space</li></ul><h4>🧪 Test It Out</h4><pre>print(firstNonRepeatingCharecter(&quot;swiss&quot;)!) // Output: w<br>print(firstNonRepeatingCharecter(&quot;aabbcc&quot;)) // Output: nil<br>print(firstNonRepeatingCharecter(&quot;teeter&quot;)) // Output: r</pre><h4>✨ Final Thoughts</h4><p>This is a neat little function that demonstrates how powerful Swift’s collections can be. By combining a dictionary with simple iteration, we can solve what appears to be a complex problem in just a few lines of code.</p><p>Got improvements in mind? Comment below! <br>There’s always more to explore. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2e6b173e257" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1 — iOS Interview Questions ( Technical Round)]]></title>
            <link>https://medium.com/@nayananp/part-1-ios-interview-questions-technical-round-447739ecb544?source=rss-cce136e72001------2</link>
            <guid isPermaLink="false">https://medium.com/p/447739ecb544</guid>
            <dc:creator><![CDATA[Nayana N P]]></dc:creator>
            <pubDate>Thu, 31 Jul 2025 12:21:05 GMT</pubDate>
            <atom:updated>2025-07-31T12:21:05.244Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 1 — iOS Interview Questions ( Technical Round)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CZhLckL7AArUiNVVoBybWw.png" /></figure><p><strong>1. What is the difference between class and struct in Swift?</strong></p><p>In Swift, classes are <strong>reference</strong> types while structs are <strong>value</strong> types. This means that when you assign a class instance to another variable, both variables refer to the same object in memory — changes in one are reflected in the other. Conversely, structs are copied on assignment, so modifying the copy won’t affect the original.</p><p>Classes support inheritance, type casting, and deinitializers, whereas structs do not.</p><p>Structs are usually preferred for small, immutable data models due to their value semantics and lower memory overhead.</p><p><strong>2. What are value types and reference types?</strong></p><p>Value types store a unique copy of data. When you assign or pass them around, Swift copies the data. Examples include struct, enum, and basic types like Int or String.</p><p>Reference types, such as class and actor, store a reference to the same instance. Multiple references to the same object can lead to unexpected changes unless handled properly. Swift encourages using value types for safety and predictability.</p><p><strong>3. What is ARC (Automatic Reference Counting)? How does it work?</strong></p><p>ARC is Swift’s memory management model that automatically keeps track of the number of strong references to class instances. When there are no more strong references to an object, it gets deallocated and memory is freed.</p><p>ARC inserts retain and release calls at compile time to manage this automatically. However, developers need to be cautious with reference cycles (e.g., two objects referencing each other) which can cause memory leaks unless resolved with weak or unowned references.</p><p><strong>4. What are strong, weak, and unowned references?</strong></p><p>A <strong>strong</strong> reference is the default in Swift and keeps an object alive as long as it’s being referenced.</p><p>A <strong>weak</strong> reference does not increase the retain count and is automatically set to nil when the object is deallocated — making it ideal for delegates and avoiding retain cycles.</p><p>An <strong>unowned</strong> reference also does not increase the retain count but assumes the object will always be in memory during its usage. If used after the object is deallocated, an unowned reference will crash the app, so it must be used carefully.</p><p>5. <strong>What is a closure in Swift?</strong></p><p>A <strong>closure</strong> is a self-contained block of functionality that can capture and store references to variables and constants from its surrounding context. Closures in Swift are similar to lambdas in other languages and can be passed as arguments, returned from functions, or assigned to variables.</p><p>Swift allows concise syntax, including trailing closures and shorthand argument names like $0. Because closures capture context, it’s important to handle memory carefully, particularly using<strong> [weak self]</strong> when referencing <strong>self</strong> inside closures to avoid retain cycles.</p><h4>6. What is a Capture List in Swift?</h4><p><strong>Capturing list</strong> is used in closures to control how variables are captured and used within a closure. When a closure is created, it can capture values from the surrounding scope. By default, a closure captures variables by reference (for reference types) or by value (for value types). A <strong>capturing list</strong> allows you to specify how each variable should be captured — whether by <strong>weak</strong>, <strong>unowned</strong>, or <strong>strong</strong> references or by <strong>value</strong> — in order to avoid potential issues like <strong>retain cycles</strong>.</p><p><strong>Why Use Capturing Lists?</strong></p><ol><li><strong>Prevent Retain Cycles</strong>: When closures capture objects by strong reference (the default behavior), it can create a <strong>retain cycle</strong>, where the closure retains the object, and the object retains the closure. This prevents either from being deallocated. Using <strong>weak</strong> or <strong>unowned</strong> references helps avoid retain cycles, especially in closures that are used in situations like delegates, notifications, or completion handlers.</li><li><strong>Control Memory Management</strong>: By specifying how variables are captured (strongly, weakly, unowned), you have more control over memory management. For example, weak references can be used to avoid retaining objects unnecessarily, while strong references are appropriate when you want to ensure an object stays alive as long as the closure is alive.</li></ol><p>•3. <strong>Performance Optimization</strong>: By controlling how closures capture variables, you can optimize performance, particularly in cases where the closure is used frequently or the captured object is large or expensive to retain.</p><h4>7. What is a pure function ?</h4><p>A pure function will always return the same output for the same set of input values. It doesn’t depend on any external state or variables. This makes the function <strong>predictable</strong>.</p><p>A pure function does not have any side effects. This means it doesn’t modify any external state, variables, or objects. It doesn’t change anything outside the scope of the function. It only computes and returns a result based on its inputs.</p><h4>Uses:</h4><p><strong>1.Testability</strong>: Since pure functions are deterministic and don’t depend on any external state, they are easy to test. You can call the function with a specific set of inputs and know exactly what the output will be.</p><p><strong>2. Referential Transparency</strong>: This is a property where an expression can be replaced by its value without changing the program’s behavior. For example, add(2, 3) can be replaced by 5 anywhere in the program.</p><p><strong>3. Concurrency</strong>: Pure functions don’t depend on external state, which makes them easier to run in parallel or in a multithreaded environment without worrying about data race issues.</p><p><strong>4. Maintainability</strong>: Pure functions are easier to reason about and maintain, as they are isolated and don’t affect or depend on other parts of the system.</p><h4>8. <strong>What does @Sendable mean?</strong></h4><p>The <strong>@Sendable</strong> attribute ensures that the closure does not capture any mutable state or resources that could cause race conditions or other concurrency issues when executed on different threads concurrently.</p><p><strong>Concurrency-Safe Closure</strong>: A closure marked as <strong>@Sendable</strong> guarantees that it can be passed safely between concurrent tasks. This means the closure can be executed in parallel (across multiple threads) without risking data races or unsafe access to shared state.</p><p><strong>Ensures No Capturing of Non-Sendable Types</strong>: When you mark a closure as <strong>@Sendable</strong>, Swift checks that the closure only captures values or references that are also safe to be shared across threads. This includes:</p><p>•<strong>Immutable data</strong> or references.</p><p>• <strong>Thread-safe objects</strong>.</p><p><strong>Prevents Unsafe Mutable Captures</strong>: The compiler will prevent closures from capturing mutable references to non-thread-safe objects or any shared mutable state. If the closure captures an unsafe reference (like an object that is mutable and not thread-safe), the compiler will produce an error.</p><p>In a concurrent environment, it’s important to ensure that closures do not accidentally modify shared state or rely on mutable objects, which could lead to race conditions, crashes, or unpredictable behavior. The <strong>@Sendable </strong>attribute makes it clear that a closure is safe to use across different concurrency contexts, allowing the compiler to enforce the proper rules and ensure the program remains safe and efficient.</p><h4>9. How does Swift handle race conditions ?</h4><p>Swift precents race consitions using:</p><ol><li>Actors( @MainActor, actor)</li><li>Isolation Mechanisms( Task, TaskGroup)</li><li>Serail Dispatch Queues( DispatchQueue.serial)</li><li>Locks &amp; Semaphores( if needed in legacy code)</li></ol><h4>10. <strong>What is the difference between frame, bounds, and center in UIKit?</strong></h4><ul><li><strong>frame</strong> defines the view’s size and position relative to its superview’s coordinate system.</li><li><strong>bounds</strong> defines the view’s size and position in its own coordinate system (usually starts at 0,0) and size.</li><li><strong>center</strong> is the point in the superview’s coordinate system where the view’s center lies.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=447739ecb544" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ How does Swift iOS programming handle race conditions ?]]></title>
            <link>https://medium.com/@nayananp/how-does-swift-ios-programming-handle-race-conditions-7ab6c1234b29?source=rss-cce136e72001------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ab6c1234b29</guid>
            <dc:creator><![CDATA[Nayana N P]]></dc:creator>
            <pubDate>Wed, 25 Jun 2025 16:27:56 GMT</pubDate>
            <atom:updated>2025-06-25T16:27:56.672Z</atom:updated>
            <content:encoded><![CDATA[<h3>🏁 How does Swift iOS programming handle race conditions ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UetIwX-A-Cmu2WmghMXS6g.png" /></figure><p>Race conditions are a classic issue in multithreaded programming, and Swift offers <strong>multiple tools and best practices</strong> to handle them effectively.</p><h4>🚨 What Is a Race Condition?</h4><p>A <strong>race condition</strong> happens when <strong>two or more threads access shared data at the same time</strong>, and at least one of them modifies it. The result depends on the timing — which is unpredictable — leading to <strong>bugs that are hard to reproduce and fix</strong>.</p><h4>✅ How Swift iOS Handles Race Conditions</h4><h4>1. Actors (Swift 5.5+) — Structured Concurrency</h4><p>Actors are Swift’s built-in solution to prevent race conditions by <strong>isolating mutable state</strong>.</p><pre>actor BankAccount {<br>    private var balance = 0<br><br>    func deposit(_ amount: Int) {<br>        balance += amount<br>    }<br><br>    func getBalance() -&gt; Int {<br>        return balance<br>    }<br>}<br><br>// Usage<br>let account = BankAccount()<br><br>Task {<br>    await account.deposit(100)<br>    let currentBalance = await account.getBalance()<br>    print(&quot;Balance: \(currentBalance)&quot;)<br>}</pre><p>🧠 <strong>Why it works</strong>: Only one task at a time can access an actor’s mutable state.</p><h4>2. Serial Dispatch Queues (GCD)</h4><p>You can use a <strong>custom serial queue</strong> to synchronize access to shared resources.</p><pre>let serialQueue = DispatchQueue(label: &quot;com.example.mySerialQueue&quot;)<br>var counter = 0<br><br>serialQueue.async {<br>    counter += 1<br>}</pre><p>🧠 <strong>Why it works</strong>: Tasks are executed one at a time in order, so no simultaneous access.</p><h4>3. Locks &amp; Semaphores (Legacy but Valid)</h4><p>You can use NSLock, NSRecursiveLock, or DispatchSemaphore to block access to shared data.</p><pre>let lock = NSLock()<br>var value = 0<br><br>lock.lock()<br>value += 1<br>lock.unlock()</pre><p>🧠 <strong>Why it works</strong>: Locks ensure only one thread can execute the critical section at a time.</p><blockquote>⚠️ Caveat: Manual locking is error-prone — can lead to <strong>deadlocks</strong> or <strong>priority inversion</strong> if not used carefully.</blockquote><h4>4. @MainActor Annotation</h4><p>When working with UI state or other shared resources, using @MainActor ensures that all access happens on the main thread.</p><pre>@MainActor class ViewModel: ObservableObject {<br>    @Published var text: String = &quot;&quot;<br>    <br>    func updateText() {<br>        text = &quot;Updated safely&quot;<br>    }<br>}</pre><p>🧠 <strong>Why it works</strong>: The main thread is inherently serial, so there’s no concurrent access.</p><h4>🎬 Summary</h4><p>Swift prevents race conditions using:</p><ul><li>Isolation Mechanisms(Task, TaskGroup)</li><li>Actors(@MainActor, actor)</li><li>Serial Dispatch Queues(DispatchQueue.serial)</li><li>Locks &amp; Semaphores(if needed in legacy code).</li><li>Locks &amp; Semaphores(if needed in legacy code).</li></ul><h3>🧪 Best Practices to Avoid Race Conditions</h3><ul><li>Use <strong>@MainActor</strong> for UI-bound logic.</li><li>Prefer <strong>structured concurrency</strong> over GCD/locks when possible.</li><li>Avoid sharing mutable state across threads without coordination.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ab6c1234b29" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Disk Caching with FileManager — iOS]]></title>
            <link>https://medium.com/@nayananp/disk-caching-with-filemanager-ios-be57cbcc63d9?source=rss-cce136e72001------2</link>
            <guid isPermaLink="false">https://medium.com/p/be57cbcc63d9</guid>
            <category><![CDATA[swift-programing-language]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[iphone-app-development]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Nayana N P]]></dc:creator>
            <pubDate>Fri, 20 Jun 2025 21:15:46 GMT</pubDate>
            <atom:updated>2025-06-20T21:15:46.576Z</atom:updated>
            <content:encoded><![CDATA[<h3>Disk Caching with FileManager — iOS</h3><h4>🔍 What It Is:</h4><p>Unlike NSCache (which only stores in memory), <strong>disk caching</strong> allows you to persist images across app launches, reducing redundant network calls and improving perceived performance.</p><h4>🧰 How It Works:</h4><ol><li>Save the image data (usually as PNG or JPEG) to a file on disk.</li><li>Use the image’s URL (or hash of it) as the filename.</li><li>On future loads, check if the image exists on disk before making a network request.</li></ol><h4>✅ Code Example:</h4><pre>func cacheDirectory() -&gt; URL {<br>    FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!<br>}<br><br>func localFilePath(for urlString: String) -&gt; URL {<br>    cacheDirectory().appendingPathComponent(urlString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? &quot;default&quot;)<br>}<br><br>func saveImageToDisk(_ image: UIImage, urlString: String) {<br>    let path = localFilePath(for: urlString)<br>    if let data = image.pngData() {<br>        try? data.write(to: path)<br>    }<br>}<br><br>func loadImageFromDisk(urlString: String) -&gt; UIImage? {<br>    let path = localFilePath(for: urlString)<br>    guard let data = try? Data(contentsOf: path) else { return nil }<br>    return UIImage(data: data)<br>}</pre><p>You can combine this with in-memory (NSCache) caching to create a <strong>two-layer cache system</strong>.</p><h3>🏷️ <strong>Adding Expiration Policies or ETag Validation</strong></h3><h4>1. 🔄 Expiration Policies</h4><p>Let’s say you want cached images to expire after 1 day.</p><p><strong>How to implement it:</strong></p><ul><li>Store metadata (e.g. Date) alongside the image file using a .json file or CoreData/SQLite.</li><li>Before returning a cached image, check the age of the file.</li><li>If it’s expired, delete and redownload.</li></ul><pre>func isImageExpired(urlString: String, expiration: TimeInterval = 86400) -&gt; Bool {<br>    let path = localFilePath(for: urlString)<br>    if let attr = try? FileManager.default.attributesOfItem(atPath: path.path),<br>       let modDate = attr[.modificationDate] as? Date {<br>        return Date().timeIntervalSince(modDate) &gt; expiration<br>    }<br>    return true<br>}</pre><h3>B. 🧾 ETag Validation (Server-Driven Caching)</h3><p>ETag (Entity Tag) is an HTTP header returned by servers to indicate content version.</p><p><strong>How it works:</strong></p><ul><li>You store the ETag received with the response.</li><li>Next time, you send the ETag back using If-None-Match header.</li><li>If the resource hasn’t changed, the server responds with <strong>304 Not Modified</strong>, saving bandwidth.</li></ul><p><strong>Benefits:</strong></p><ul><li>More accurate than time-based expiration.</li><li>Server controls when content is stale.</li></ul><p><strong>Example (using URLRequest):</strong></p><pre>var request = URLRequest(url: URL(string: urlString)!)<br>request.addValue(etag, forHTTPHeaderField: &quot;If-None-Match&quot;)<br><br>URLSession.shared.dataTask(with: request) { data, response, _ in<br>    if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 304 {<br>        // Not modified, use cached image<br>    } else {<br>        // Downloaded new data, update cache and etag<br>    }<br>}.resume()</pre><p>You need to manage ETag storage (e.g., using UserDefaults or a small cache DB).</p><h3>🧠 Summary:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_jZ5KgJj5sbA1279fh1iBA.png" /></figure><p>Have questions or comments? Leave a comment or reach out on <a href="https://www.linkedin.com/nayananp17">LinkedIn</a>.✍️ Nayana N P<br>📬 Follow me for more Swift deep dives, coding tips, and clean code write-ups!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be57cbcc63d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering UIScrollView in Storyboard: Avoid Constraint Ambiguity Once and For All]]></title>
            <link>https://medium.com/@nayananp/mastering-uiscrollview-in-storyboard-avoid-constraint-ambiguity-once-and-for-all-90dc789d9572?source=rss-cce136e72001------2</link>
            <guid isPermaLink="false">https://medium.com/p/90dc789d9572</guid>
            <category><![CDATA[scrollview]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[uikit]]></category>
            <dc:creator><![CDATA[Nayana N P]]></dc:creator>
            <pubDate>Sun, 08 Jun 2025 12:51:19 GMT</pubDate>
            <atom:updated>2025-06-08T12:51:19.619Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hGnYUU-7b1KEChTIZ6snxQ.png" /></figure><p>Adding a UIScrollView in Interface Builder (Storyboard) is one of those tasks in iOS development that seems easy—but often leads to frustrating constraint errors like:</p><blockquote><em>“Ambiguous scrollable content height”</em></blockquote><p>Here’s a step-by-step visual guide to setting up a scroll view <strong>properly</strong> so you can scroll content smoothly without Auto Layout headaches.</p><h4>Step 1: Add UIScrollView and Pin It</h4><p>Drag a UIScrollView into your View Controller’s main view.</p><p><strong>Pin it to the Safe Area</strong> or Superview on all four sides:</p><ul><li>Top: 0</li><li>Bottom: 0</li><li>Leading: 0</li><li>Trailing: 0</li></ul><p>This anchors your scroll view to the visible screen area.</p><h4>Step 2: Add a UIView Inside ScrollView (Content View)</h4><p>Drag a plain UIView inside the UIScrollView. This will become your <strong>content view</strong>.</p><p>Set 4 constraints <strong>between the content view and the scroll view</strong>:</p><ul><li>Leading = Scroll View Leading</li><li>Trailing = Scroll View Trailing</li><li>Top = Scroll View Top</li><li>Bottom = Scroll View Bottom</li></ul><p>This defines the scroll view’s content area.</p><h4>Step 3: Set Equal Width Constraint</h4><p>To avoid ambiguity, constrain the content view’s width to match the scroll view:</p><ul><li>Control-drag from contentView to scrollView</li><li>Select <strong>Equal Widths</strong></li></ul><blockquote><em>If you want horizontal scrolling instead, constrain </em><strong><em>height</em></strong><em> instead of width.</em></blockquote><h4>Step 4: Add Content and Pin It</h4><p>Drag labels, buttons, images, etc. into the content view.</p><p>Pin these to the content view’s edges.</p><p><strong>Important:</strong></p><ul><li>Your bottom-most element must have a <strong>bottom constraint to the content view</strong>.</li></ul><p>This defines the scrollable height.</p><h4>Common Mistakes to Avoid</h4><h4>❌ Adding elements directly into the scroll view</h4><p>Always use a content view inside the scroll view.</p><h4>❌ Missing the equal width/height constraint</h4><p>This results in ambiguity for Auto Layout.</p><h4>❌ No bottom constraint</h4><p>Without it, the scroll view doesn’t know how far to scroll.</p><h4>Bonus Tip: Keyboard-Aware Scrolling</h4><p>If your scroll view includes text fields, be sure to handle keyboard appearance by adjusting content insets.</p><p>Apple’s documentation: <a href="https://developer.apple.com/documentation/uikit/uiscrollview">UIScrollView — Adjusting for Keyboard</a></p><h4>You’re All Set!</h4><p>With this setup, your scroll views in Storyboard should now work flawlessly, avoiding constraint errors.</p><p>Have questions or comments? Leave a comment or reach out on <a href="https://www.linkedin.com/nayananp17">LinkedIn</a>.</p><p>✍️ Nayana N P<br>📬 Follow me for more Swift deep dives, coding tips, and clean code write-ups!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90dc789d9572" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[️ Image Caching in iOS (Swift)]]></title>
            <link>https://medium.com/@nayananp/%EF%B8%8F-image-caching-in-ios-swift-c5b1ad5d23c8?source=rss-cce136e72001------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5b1ad5d23c8</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[swift-programming]]></category>
            <dc:creator><![CDATA[Nayana N P]]></dc:creator>
            <pubDate>Sat, 10 May 2025 19:19:06 GMT</pubDate>
            <atom:updated>2025-05-10T19:19:06.792Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c_NieMUQM9xyUCcw7ZnVKQ.png" /></figure><h4>🔍 What is Image Caching?</h4><p>Image caching is the process of <strong>saving downloaded images</strong> locally (in memory or on disk) so you don’t have to download them again every time they’re needed. This makes your app <strong>faster</strong> and reduces <strong>network usage</strong>.</p><h4>✅ Why Use It?</h4><ul><li>Avoid repeated downloads</li><li>Improve scrolling performance in lists (like in UICollectionView or UITableView)</li><li>Reduce network load and battery usage</li></ul><h4>📦 Common Caching Options:</h4><ul><li><strong>NSCache</strong> — In-memory cache. Automatically removes objects under memory pressure.</li><li><strong>FileManager</strong> — Save to disk if you want persistent caching between app launches.</li><li><strong>Third-party Libraries</strong> — Like <a href="https://github.com/onevcat/Kingfisher">Kingfisher</a> or <a href="https://github.com/SDWebImage/SDWebImage">SDWebImage</a> that do all the heavy lifting.</li></ul><p>🧠 Basic Example Using NSCache:</p><pre>class ImageCache {<br>    static let shared = NSCache&lt;NSString, UIImage&gt;()<br>}</pre><p>Usage in a view controller:</p><pre>let urlString = &quot;https://example.com/image.jpg&quot;<br><br>if let cachedImage = ImageCache.shared.object(forKey: urlString as NSString) {<br>    imageView.image = cachedImage<br>} else {<br>    URLSession.shared.dataTask(with: URL(string: urlString)!) { data, response, error in<br>        guard let data = data, let image = UIImage(data: data) else { return }<br>        <br>        // Cache it<br>        ImageCache.shared.setObject(image, forKey: urlString as NSString)<br>        <br>        // Set image on main thread<br>        DispatchQueue.main.async {<br>            imageView.image = image<br>        }<br>    }.resume()<br>}</pre><h4>🧵 Concurrency in Image Loading</h4><p>Concurrency ensures that <strong>downloading images</strong> doesn’t block the main thread (UI stays smooth).</p><h4>✅ Tools for Concurrency in Swift:</h4><ul><li>URLSession with completion handler (basic)</li><li>DispatchQueue (for thread management)</li><li>async/await (Swift Concurrency – clean and modern way)</li></ul><h4>💡 Example with async/await (iOS 15+):</h4><pre>func fetchImage(from urlString: String) async -&gt; UIImage? {<br>    if let cachedImage = ImageCache.shared.object(forKey: urlString as NSString) {<br>        return cachedImage<br>    }<br><br>    guard let url = URL(string: urlString),<br>          let (data, _) = try? await URLSession.shared.data(from: url),<br>          let image = UIImage(data: data) else {<br>        return nil<br>    }<br><br>    ImageCache.shared.setObject(image, forKey: urlString as NSString)<br>    return image<br>}</pre><p>Then you’d use it in your view controller:</p><pre>Task {<br>    if let image = await fetchImage(from: &quot;https://example.com/image.jpg&quot;) {<br>        imageView.image = image<br>    }<br>}</pre><h4>⚖️ Summary</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TKGlOSmd91NsTMPiFchKbA.png" /></figure><p>✍️ Nayana N P<br> 📬 Follow me for more Swift deep dives, coding tips, and clean code write-ups!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5b1ad5d23c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>