<?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 Shreeya on Medium]]></title>
        <description><![CDATA[Stories by Shreeya on Medium]]></description>
        <link>https://medium.com/@shreeya28?source=rss-8466439f74c4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*yjapfyOW-W2fWnEo</url>
            <title>Stories by Shreeya on Medium</title>
            <link>https://medium.com/@shreeya28?source=rss-8466439f74c4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 10:52:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shreeya28/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[Copy on write in swift]]></title>
            <link>https://shreeya28.medium.com/copy-on-write-in-swift-4b4efdd165ea?source=rss-8466439f74c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b4efdd165ea</guid>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Shreeya]]></dc:creator>
            <pubDate>Mon, 27 May 2024 12:54:47 GMT</pubDate>
            <atom:updated>2024-05-27T12:56:33.569Z</atom:updated>
            <content:encoded><![CDATA[<p>In the absence of mutation, values and references act exactly the same way.</p><p>Copy-on-write (CoW) is a memory management technique used in programming languages like Swift to optimize the performance of value types, such as arrays and dictionaries. When you create a copy of a value type, the actual copying of the data is deferred until one of the copies is modified. This can be more efficient than immediately duplicating the data.</p><p>In Swift, when you have a value type like an array, and you make a copy of it, both the original array and the copy initially point to the same memory location. When you modify one of the arrays, Swift checks if it’s the sole owner of the underlying memory. If it is, it can modify the data in place. However, if there are multiple owners (i.e., multiple references to the same array), Swift creates a new copy of the array’s data and then performs the modification. This ensures that the original array and any other copies remain unaffected by the change.</p><p>Now, the issue arises when multiple threads or concurrent tasks are involved. When one thread is reading an array while another thread is concurrently modifying it, the behavior depends on how the array is being modified and how Swift’s copy-on-write mechanism handles the situation.</p><p><strong>Concurrent Write and Read</strong></p><p>Here’s where things get tricky. In Swift, when you have a value type like an array (which is a struct), and you modify it, the copy-on-write mechanism kicks in. This means that if the array is being modified, and there are other references to it, a new copy of the array’s data is created to ensure that the modification doesn’t affect other references.</p><p>Here’s where the issue arises. While the modifying thread is creating a new copy of the array’s data, the reading thread might still be referencing the old data. If the modifying thread completes the write operation (thus deallocating the old storage), and if the reading thread attempts to access the array after this deallocation, it will end up trying to reference memory that has been deallocated, leading to a crash.</p><p>To put it simply, the crash occurs because the reading thread is trying to access memory that no longer exists. This is because the modifying thread has already created a new copy of the array’s data, leaving the old storage deallocated.</p><p>To avoid such crashes, it’s essential to ensure proper synchronization between threads when accessing shared mutable state like arrays. This can be achieved using synchronization mechanisms such as locks, queues, or Swift’s concurrency features to coordinate access and prevent race conditions.</p><p>Source:</p><p><a href="https://developer.apple.com/swift/blog/?id=10">Value and Reference Types - Swift Blog</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b4efdd165ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic ScrollView in Xcode 12]]></title>
            <link>https://shreeya28.medium.com/dynamic-scrollview-in-xcode-12-a7fb3d64de39?source=rss-8466439f74c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7fb3d64de39</guid>
            <dc:creator><![CDATA[Shreeya]]></dc:creator>
            <pubDate>Tue, 06 Jul 2021 11:44:12 GMT</pubDate>
            <atom:updated>2021-07-06T11:44:12.071Z</atom:updated>
            <content:encoded><![CDATA[<p>Dynamic ScrollView in Xcode 12</p><p>In this post i will explain how to implement a dynamic scrollview using storyboard.</p><ol><li>Create new Xcode project.</li><li>Head over to the storyboard.</li><li>In the object library , search for “ UIScrollview”. Place it inside the ViewController.Set scroll view constraint (top, bottom, leading and trailing) as (0,0,0,0).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*B31XN67UyIYlpSvqGapI5A.png" /><figcaption>Scroll View constraints</figcaption></figure><p><strong>uncheck / Disable the content layout guides in the size inspector tab.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*UGFO_WhH_jveMIl3H2sozA.png" /></figure><p>4. Search for “UIView” in the library , place it inside the scrollview. Set constraint (top, bottom, leading and trailing) as (0,0,0,0).For better understanding, name this view as containerView.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*bNN7M_xyzMegzLBgIn45sQ.png" /></figure><p>5. Set <strong>Container</strong> view width = <strong>scrollview</strong> width and <strong>container</strong> view height = <strong>mainview</strong> height . set height priority to 250.Please ensure that the multiplier property is set to one for height and width both .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*XqO8qBYS9BgYAfbJwfjCSA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*YiVKuWA6bXZk1up9rOh6tg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*tAAbUlglTd3ZiHd1Jy3FsA.png" /></figure><p>6. Place a UIView inside container view and give (Top , leading and trailing ) (0,0,0)and height constraint .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*GypZ6R4p6WtbMdjzD0JNLg.png" /></figure><p>now, the important point to keep in mind is you <strong>need</strong> to provide the bottom constraint of <strong>last</strong> view for the scrollview to work properly.</p><p>so place as many uiviews as you like ,provide constaints and give bottom constraint to the last view w.r.t the container view and you are good to go!</p><p>If you have any doubts , i have attached the video of this project below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*QsWa4zpNACjS9T_tsTvTBg.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FlUU05Vt95qI&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DlUU05Vt95qI&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e380025c4a3fa86f8dd3a7421a1bcbb1/href">https://medium.com/media/e380025c4a3fa86f8dd3a7421a1bcbb1/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7fb3d64de39" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>