<?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 Karthik Sankar on Medium]]></title>
        <description><![CDATA[Stories by Karthik Sankar on Medium]]></description>
        <link>https://medium.com/@karthiks01?source=rss-dadae3fa0bc7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*S69KYggFMZJPb0nAd-ZdRw.jpeg</url>
            <title>Stories by Karthik Sankar on Medium</title>
            <link>https://medium.com/@karthiks01?source=rss-dadae3fa0bc7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 21:31:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@karthiks01/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[Structs vs Classes in Swift: Understanding Memory Allocation]]></title>
            <link>https://medium.com/code10-one/structs-vs-classes-in-swift-understanding-memory-allocation-9b80847081ae?source=rss-dadae3fa0bc7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b80847081ae</guid>
            <dc:creator><![CDATA[Karthik Sankar]]></dc:creator>
            <pubDate>Mon, 25 Nov 2024 06:19:55 GMT</pubDate>
            <atom:updated>2024-11-25T06:19:55.707Z</atom:updated>
            <content:encoded><![CDATA[<p>Swift gives developers the flexibility to choose between <strong>structs</strong> and <strong>classes</strong> when defining data types. While they often seem interchangeable, a key difference lies in how they use <strong>heap</strong> and <strong>stack</strong> memory. Let’s explore these differences and how they impact performance.</p><h3>1. Structs and Stack Memory</h3><ul><li><strong>Structs</strong> are <strong>value types</strong> in Swift, meaning they are copied when assigned or passed around.</li><li>They are stored on the <strong>stack</strong>, a region of memory known for fast allocation and deallocation.</li><li><strong>Advantages</strong>:</li><li>No need for reference counting (ARC), resulting in faster operations.</li><li>Automatically thread-safe because each instance is independent.</li><li><strong>Example</strong>:</li></ul><pre>struct Point {     var x: Int     var y: Int } var p1 = Point(x: 5, y: 10) var p2 = p1 // Creates a copy p2.x = 15 print(p1.x) // Output: 5 (original remains unaffected)</pre><h3>2. Classes and Heap Memory</h3><ul><li><strong>Classes</strong> are <strong>reference types</strong>. When assigned or passed, they don’t copy the data but share a reference to the same instance.</li><li>They are stored on the <strong>heap</strong>, which has dynamic memory allocation managed by <strong>ARC</strong> (Automatic Reference Counting).</li><li><strong>Advantages</strong>:</li><li>Ideal for sharing mutable data between parts of an app.</li><li>Allow inheritance, making them suitable for complex object hierarchies.</li><li><strong>Example</strong>:</li></ul><pre>class Point {     var x: Int     var y: Int     init(x: Int, y: Int) {         self.x = x         self.y = y     } } var p1 = Point(x: 5, y: 10) var p2 = p1 // Points to the same instance p2.x = 15 print(p1.x) // Output: 15 (both refer to the same object)</pre><h3>3. Key Differences Between Heap and Stack</h3><p><strong>Aspect</strong> <strong>Stack</strong> <strong>Heap</strong> <strong>Data Type</strong> Structs (Value Types) Classes (Reference Types) <strong>Allocation</strong> Fixed and fast Dynamic and slower <strong>Ownership</strong> Copies data Shares references <strong>ARC Involvement</strong> None Required for reference counting <strong>Thread Safety</strong> Safer due to immutability by copy Requires careful management</p><h3>4. When to Use Structs vs Classes</h3><ul><li><strong>Use Structs</strong> when:</li><li>The data is immutable or needs to be independent.</li><li>Performance is critical, and you want minimal ARC overhead.</li><li>You’re working with simple data models like coordinates or settings.</li><li><strong>Use Classes</strong> when:</li><li>The object’s lifetime needs to be shared across multiple parts of your app.</li><li>You require inheritance or polymorphism.</li><li>You need dynamic, mutable data structures.</li></ul><h3>5. Use Case: Performance Comparison</h3><p>Imagine creating a game where you track the position of multiple objects. Using <strong>structs</strong> for positions ensures fast stack-based memory allocation, reducing ARC overhead. Conversely, classes might be ideal for shared, dynamically changing objects like game levels or configurations.</p><h3>6. Debugging Tip</h3><p>Use LLDB commands like frame variable in Xcode to observe memory allocation during runtime. It’s a handy way to see how structs live on the stack and classes on the heap.</p><p>This article provides clear, actionable insights and aligns with your Medium blog’s focus on practical iOS development tips. Let me know if you need additional examples or refinements!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b80847081ae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code10-one/structs-vs-classes-in-swift-understanding-memory-allocation-9b80847081ae">Structs vs Classes in Swift: Understanding Memory Allocation</a> was originally published in <a href="https://medium.com/code10-one">Code10.one — A Weekly iOS Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering iOS Debugging: Understanding po, p, and v in LLDB]]></title>
            <link>https://medium.com/code10-one/mastering-ios-debugging-understanding-po-p-and-v-in-lldb-e794e1dda5d2?source=rss-dadae3fa0bc7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e794e1dda5d2</guid>
            <dc:creator><![CDATA[Karthik Sankar]]></dc:creator>
            <pubDate>Mon, 25 Nov 2024 06:15:57 GMT</pubDate>
            <atom:updated>2024-11-25T06:15:57.854Z</atom:updated>
            <content:encoded><![CDATA[<p>Debugging is an art every iOS developer must master, and LLDB (Low-Level Debugger) is your toolbox for resolving complex issues. Today, we’ll break down three fundamental LLDB commands — po, p, and v—their differences, and a practical use case to showcase their power.</p><h3>1. What Does po Do?</h3><ul><li><strong>po</strong> stands for <strong>Print Object</strong>.</li><li>It prints the result using the <strong>description</strong> or <strong>debugDescription</strong> of the object.</li><li>Best suited for <strong>human-readable output</strong> of Swift and Objective-C objects.</li></ul><h4>Example:</h4><pre>let array = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]<br>po array<br>// Output: [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]</pre><h4>Use Case:</h4><ul><li>Debugging collections like arrays or dictionaries to inspect their contents.</li></ul><h3>2. The Role of p</h3><ul><li><strong>p</strong> stands for <strong>Print</strong> and evaluates an expression in the current context.</li><li>Prints <strong>raw data</strong> or <strong>evaluated expressions</strong>, ideal for primitives and pointers.</li></ul><h4>Example:</h4><pre>let number = 42<br>p number<br>// Output: (Int) $R0 = 42</pre><h4>Use Case:</h4><ul><li>Investigating primitive values or pointers when detailed evaluation isn’t necessary.</li></ul><h3>3. What About v?</h3><ul><li><strong>v</strong> stands for <strong>Variable</strong> and shows the raw value of a variable as stored in memory.</li><li>Unlike po or p, it doesn’t evaluate expressions.</li></ul><h4>Example:</h4><pre>var name = &quot;John Doe&quot;<br>v name<br>// Output: (String) name = &quot;John Doe&quot;</pre><h4>Use Case:</h4><ul><li>Viewing variable snapshots without computation, especially helpful in low-level debugging.</li></ul><h3>4. The Key Differences</h3><p>Command Purpose Output Context <strong>po</strong> Human-readable object output description or debugDescription Swift, Objective-C <strong>p</strong> Raw data or evaluated expression Data with type information Swift, primitives <strong>v</strong> Raw variable values Current state in memory Low-level debugging.</p><h3>5. Debugging Takeaway</h3><p>Using po, p, and v effectively saves time and helps pinpoint issues efficiently. By mastering these commands, you can quickly interpret data at various levels of abstraction and resolve bugs faster.</p><h4>Stay Updated!</h4><p>Follow more debugging tips and tricks at <a href="https://blog.code01.one/"><strong>blog.code01.one</strong></a>.</p><p>Happy debugging, and see you in the code! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e794e1dda5d2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code10-one/mastering-ios-debugging-understanding-po-p-and-v-in-lldb-e794e1dda5d2">Mastering iOS Debugging: Understanding po, p, and v in LLDB</a> was originally published in <a href="https://medium.com/code10-one">Code10.one — A Weekly iOS Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>