<?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 Pawan Manjani on Medium]]></title>
        <description><![CDATA[Stories by Pawan Manjani on Medium]]></description>
        <link>https://medium.com/@manjani-pavan?source=rss-1306b6bf47c4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*JG0_2umvBlYLPru6TRCrBg.jpeg</url>
            <title>Stories by Pawan Manjani on Medium</title>
            <link>https://medium.com/@manjani-pavan?source=rss-1306b6bf47c4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 00:57:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manjani-pavan/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[Task.immediate in Swift 6.2]]></title>
            <link>https://manjani-pavan.medium.com/task-immediate-in-swift-7bdf8801a9ab?source=rss-1306b6bf47c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bdf8801a9ab</guid>
            <category><![CDATA[immediatetask]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[taskimmediate]]></category>
            <category><![CDATA[tasks]]></category>
            <dc:creator><![CDATA[Pawan Manjani]]></dc:creator>
            <pubDate>Sat, 02 May 2026 11:15:55 GMT</pubDate>
            <atom:updated>2026-05-02T11:41:10.945Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*X9mI7vv19zeGUTh-qLPTWg.png" /></figure><p>Swift 6.2 has already been released, and I came across an interesting feature in it.</p><p>Swift’s new immediate tasks start running right away in the caller’s context until they pause, unlike regular tasks that just get queued to run later — making them faster for performance-sensitive code.</p><p>Let’s start with regular Task:</p><pre>Task {<br>   print(&quot;Data 1&quot;)<br>}<br>print(&quot;Data 2&quot;)<br><br>/* output will be<br>Data 2<br>Data 1<br>*/</pre><p>Let’s start by using Task.immediate:</p><pre>Task.immediate {<br>   print(&quot;Data 1&quot;)<br>}<br>print(&quot;Data 2&quot;)<br><br>/* output will be<br>Data 1<br>Data 2<br>*/</pre><figure><img alt="Gif Source: https://giphy.com" src="https://cdn-images-1.medium.com/max/374/1*WT2QWnR_cC0SyzM1jArJnw.gif" /><figcaption>Gif Source: <a href="https://giphy.com/">https://giphy.com</a></figcaption></figure><p>Another example using both together:</p><pre>Task.immediate {<br>   print(&quot;Data&quot;)<br>}<br>Task {<br>   print(&quot;Data 1&quot;)<br>}<br>print(&quot;Data 2&quot;)<br><br>/* output will be<br>Data<br>Data 2<br>Data 1<br>*/</pre><p>Suppose I have async func inside Task.immediate:</p><pre>Task.immediate {<br>   print(&quot;Data&quot;)<br>   let userCount = await getUserData()<br>   print(userCount)<br>}<br>print(&quot;Data 2&quot;)<br>/* output will be<br>Data<br>Data 2<br>200 --&gt; this is usercount<br>*/</pre><p>Task.immediate ensures the task begins synchronously, but that doesn’t mean it will finish synchronously.</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong>Please like and follow for more</strong></p><p><em>Thanks for reading, Happy Coding 💻</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bdf8801a9ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[@Observable in SwiftUI]]></title>
            <link>https://manjani-pavan.medium.com/observable-in-swiftui-d90ff6252ec2?source=rss-1306b6bf47c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d90ff6252ec2</guid>
            <category><![CDATA[ios-17]]></category>
            <category><![CDATA[observables]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[observableobject]]></category>
            <dc:creator><![CDATA[Pawan Manjani]]></dc:creator>
            <pubDate>Sat, 14 Sep 2024 06:50:02 GMT</pubDate>
            <atom:updated>2024-09-14T07:06:06.571Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*X9mI7vv19zeGUTh-qLPTWg.png" /></figure><p>The @Observable macro, introduced at WWDC 2023 and supported from <strong>iOS17 onwards</strong>, it replaces ObservableObject and @Published properties. It automatically triggers SwiftUI view updates when any changes occurs.</p><p>Let’s move to the code</p><p>Before @Observable macro</p><pre>// View<br>struct ContentView: View {<br>    @StateObject var vm: ViewModel = ViewModel()<br>    var body: some View {<br>        VStack {<br>            Text(&quot;Hello, world \(vm.count)&quot;)<br>            Button {<br>                vm.count += 1<br>            } label: {<br>                Text(&quot;Click me&quot;)<br>            }<br>        }<br>        .padding()<br>    }<br>}<br>// Viewmodel<br>final class ViewModel: ObservableObject {<br>    @Published var count: Int =  0<br>}</pre><p>After implementing @Observable macro</p><pre>// View<br>struct ContentView: View {<br>    let vm: ViewModel = ViewModel()<br>    var body: some View {<br>        VStack {<br>            Text(&quot;Hello, world \(vm.count)&quot;)<br>            Button {<br>                vm.count += 1<br>            } label: {<br>                Text(&quot;Click me&quot;)<br>            }<br>        }<br>        .padding()<br>    }<br>}<br>// Viewmodel<br>@Observable<br>final class ViewModel {<br>   var count: Int =  0<br>}</pre><p>Let see the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*wBoNX1cQvk9_c0M6Y1ReRw.gif" /></figure><p>Simple and easy right???? 😉</p><p>If you right click @Observable macro and click on Refactor-&gt;Inline Macro then you see below code.</p><pre>final class ViewModel {<br>    @ObservationTracked var count: Int =  0<br>    <br>    <br>    @ObservationIgnored private let _$observationRegistrar = Observation.ObservationRegistrar()<br>    <br>    internal nonisolated func access&lt;Member&gt;(<br>        keyPath: KeyPath&lt;ViewModel , Member&gt;<br>    ) {<br>        _$observationRegistrar.access(self, keyPath: keyPath)<br>    }<br>    <br>    internal nonisolated func withMutation&lt;Member, MutationResult&gt;(<br>        keyPath: KeyPath&lt;ViewModel , Member&gt;,<br>        _ mutation: () throws -&gt; MutationResult<br>    ) rethrows -&gt; MutationResult {<br>        try _$observationRegistrar.withMutation(of: self, keyPath: keyPath, mutation)<br>    }<br>}<br><br>extension ViewModel: Observation.Observable {<br>}</pre><p><strong>Please like and follow for more</strong></p><p><em>Thanks for reading, Happy Coding 💻</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d90ff6252ec2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DynamicProperty in SwiftUI]]></title>
            <link>https://manjani-pavan.medium.com/dynamicproperty-in-swiftui-c026853ad364?source=rss-1306b6bf47c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c026853ad364</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[dynamic-property]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Pawan Manjani]]></dc:creator>
            <pubDate>Tue, 27 Aug 2024 11:36:54 GMT</pubDate>
            <atom:updated>2024-08-27T11:36:54.831Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*_rZOOQbJDBaUtEQBHrggxw.jpeg" /></figure><p>In SwiftUI, we have property wrappers like @State, @StateObject, and @AppStorage. Additionally, we can create our own custom property wrappers.</p><pre>@propertyWrapper<br>struct Uppercased {<br>    @State var wrappedValue: String<br>    var projectedValue: Binding&lt;String&gt; {<br>        Binding(<br>            get: {<br>                return wrappedValue.uppercased()<br>            },<br>            set: { newValue in<br>                wrappedValue = newValue.uppercased()<br>            }<br>        )<br>    }<br>}</pre><p>Which we can use in our SwiftUI like below:</p><pre>@uppercased var name: String = &quot;&quot;</pre><p>and the full code of the SwiftUI view is below:</p><pre>struct ContentView: View {<br>    @Uppercased var name: String = &quot;&quot;<br>    var body: some View {<br>        VStack {<br>            Text(&quot;Hello, \(name)&quot;)<br>            TextField(&quot;Enter here&quot;, text: $name)<br>        }<br>        .padding()<br>    }<br>}</pre><p>I hope if we run this code and our new changes will be updated to Text view runtime. Let’s run the code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*bAWECb3K80EMK8lm4ed0vg.gif" /></figure><p>As we can see, the name is not appearing when we enter it.</p><p>Here comes <strong>DynamicProperty</strong> to help us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*SF-a95d5d6xkhqTTIAIz2g.gif" /></figure><p>Just conform <strong>DynamicProperty</strong> protocol to the struct of property wrapper like below:</p><pre>struct Uppercased: DynamicProperty { //Here<br>    @State var wrappedValue: String<br>    var projectedValue: Binding&lt;String&gt; {<br>        Binding(<br>            get: {<br>                return wrappedValue.uppercased()<br>            },<br>            set: { newValue in<br>                wrappedValue = newValue.uppercased()<br>            }<br>        )<br>    }<br>    func update() { // This is called when the view will evaluate its body.<br>        print(&quot;update called&quot;)<br>    }<br>}</pre><p>So after adding this let’s run the code and see the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*vhYeIYzQQ59c1kd5gUQW8w.gif" /></figure><p>You can include <strong>@StateObject</strong> properties within your property wrapper to trigger updates in your views.</p><p><strong>Please like and follow for more</strong></p><p><em>Thanks for reading, Happy Coding 💻</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c026853ad364" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Consume operator in Swift 5.9]]></title>
            <link>https://manjani-pavan.medium.com/consume-operator-in-swift-5-9-a36fe162e567?source=rss-1306b6bf47c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a36fe162e567</guid>
            <category><![CDATA[consume]]></category>
            <category><![CDATA[consume-operator]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[consume-in-swift]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Pawan Manjani]]></dc:creator>
            <pubDate>Mon, 08 Jan 2024 15:54:58 GMT</pubDate>
            <atom:updated>2024-01-08T15:54:58.347Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*pVqwYlnZLkRHA6fVd1kP1Q.jpeg" /></figure><p>In Swift 5.9 we got new operator <strong>consume</strong> which helps us to handle Copy On Write (COW) data structures and reduce retain/release calls.</p><p>Suppose you have function which you are passing the local variable to another function then again the next function is passing that variable to another function and so on… this will not allow to release first func variable until it is being used somewhere with any function</p><p>So here <strong>consume</strong> will help us here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*g0_gBCA2AOEjQnMrsQ1HaA.gif" /><figcaption>Gif Source: <a href="https://giphy.com/">https://giphy.com</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QD6tD-fi9_fbO8ZRdjLJDw.png" /></figure><p>In above code if we are trying to access the arry after consume then compiler will not allow us to do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KTNc-JAt3V4aTR9AUgvLDA.png" /></figure><p>Now compiler is happy because we are using new variable newArr variable</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PXelKboLhfcdSzFNKuTdBQ.png" /></figure><p>But we can reinitialize the variable and use it again.</p><p>What if we use consume with global variable????</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-bPHcqAhGscmSG35dRrypQ.png" /></figure><p>Compiler will throw error that we can use only consume with local variables.</p><p><strong>For more detail </strong><br><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md">https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md</a></p><p><strong>Please like and follow for more</strong></p><p><em>Thanks for reading, Happy Coding 💻</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a36fe162e567" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Repeat loop in Swift]]></title>
            <link>https://manjani-pavan.medium.com/repeat-loop-in-swift-cd2b4bcad2d2?source=rss-1306b6bf47c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd2b4bcad2d2</guid>
            <category><![CDATA[loops-in-swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[loop]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[repeatloop]]></category>
            <dc:creator><![CDATA[Pawan Manjani]]></dc:creator>
            <pubDate>Sun, 24 Dec 2023 09:38:56 GMT</pubDate>
            <atom:updated>2023-12-24T09:38:56.678Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*pVqwYlnZLkRHA6fVd1kP1Q.jpeg" /></figure><p>As we know we having <strong>for loop</strong> and <strong>while loop</strong> in swift for writing loops but also we have <strong>repeat loop</strong>.</p><p>In repeat loop the loop block will be execute at least once even condition get fails.</p><pre>repeat {<br>print(&quot;block executed&quot;)<br>} while number &gt; 0<br><br>/* Output will be <br>block executed<br>*/</pre><p>In above example even condition is false but still block will be execute once because condition will be execute at the end of the repeat loop code.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FQUENDfi6DEMLzQ0CKt%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FQUENDfi6DEMLzQ0CKt%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExMTc4eDFxeWh3ZnM3M3U1NXU0MGgxNXg3Y3dqOGN6bGh2aWpmYm1sYSZlcD12MV9naWZzX2dpZklkJmN0PWc%2FQUENDfi6DEMLzQ0CKt%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="324" frameborder="0" scrolling="no"><a href="https://medium.com/media/199d0a58a9bd33474425ca217f6a5fbc/href">https://medium.com/media/199d0a58a9bd33474425ca217f6a5fbc/href</a></iframe><p>Let’s have one more example</p><pre>var number = 1<br>repeat {<br>   print(number)<br>   number += 1<br> } while number &lt; 5<br><br>/* Output will be <br>1<br>2<br>3<br>4<br>*/</pre><p><strong>Please like and follow me for more</strong></p><p><em>Thanks for reading, Happy Coding 💻</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd2b4bcad2d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KeyboardLayoutGuide in iOS15*]]></title>
            <link>https://manjani-pavan.medium.com/keyboardlayoutguide-in-ios15-8a47ed93ba96?source=rss-1306b6bf47c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a47ed93ba96</guid>
            <category><![CDATA[keyboardlayoutguide]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[keyboard]]></category>
            <category><![CDATA[ios15]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Pawan Manjani]]></dc:creator>
            <pubDate>Sun, 24 Sep 2023 16:05:52 GMT</pubDate>
            <atom:updated>2023-10-05T10:05:18.650Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*w7-L62cxti22KkPi3fCwQg.jpeg" /></figure><blockquote><a href="https://developer.apple.com/documentation/uikit/uiview/3752221-keyboardlayoutguide">Apple says</a> A layout guide that tracks the keyboard’s position in your app’s layout.</blockquote><p>In simple words KeyboardLayoutGuide help us to setup view frame according to the keyboard position when keyboard appears in the screen.</p><p>Before iOS15 we use to import <a href="https://github.com/hackiftekhar/IQKeyboardManager">IQKeyboardManager</a> in our project to adjust our view when keyboard appears in our application’s view and it’s very wonderful library to use or we used to manually set up a NotificationCenter to adjust our view when keyboard appears. But now we have KeyboardLayoutGuide to help us here.</p><p>Let me show you an example</p><pre>yourView.bottomAnchor.constraint(equalTo: self.view.keyboardLayoutGuide.bottomAnchor).isActive = true</pre><p>In above code we given bottomAnchor of our view constraint to keyboardLayoutGuide’s bottomAnchor and just it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*rnurNoxJu8GjK4c9gfz46A.gif" /><figcaption>Source <a href="https://gifer.com/">https://gifer.com</a></figcaption></figure><blockquote>What if I want to use in storyboard?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*ORzX1NAR5Qih_dWQehL6sQ.png" /></figure><ol><li>Select your main view and go to size inspector and then select Keyboard checkbox</li><li>Give your view’s bottom constraint to KeyboardLayoutGuide’s top</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*flRJN4xuzTLc1Z3u1m8Rrw.png" /></figure><h4>Just it!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hDFf7LkTr6LXyG-lJa0nNw.gif" /></figure><p><strong>For more visit: </strong><a href="https://ioslifee.blogspot.com/"><strong>https://ioslifee.blogspot.com</strong></a></p><p><em>Thanks for reading, Happy Coding 💻</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a47ed93ba96" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CollectionOfOne in Swift]]></title>
            <link>https://manjani-pavan.medium.com/collectionofone-in-swift-776591e8e8e4?source=rss-1306b6bf47c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/776591e8e8e4</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[collectionofone]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[collection]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Pawan Manjani]]></dc:creator>
            <pubDate>Tue, 04 Jul 2023 15:47:03 GMT</pubDate>
            <atom:updated>2023-07-04T15:47:03.614Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*83XOVvQYAk14L8TIVh_jdA.png" /></figure><blockquote>Apple says: You can use a CollectionOfOne instance when you need to efficiently represent a single value as a collection.</blockquote><p>In simple words by using <strong>CollectionOfOne</strong> we can use any single value as <a href="https://developer.apple.com/documentation/swift/collections">collection</a></p><p>Suppose take an Example I have array of users :</p><pre>let arrUsers = [&quot;Pawan&quot;, &quot;John&quot;, &quot;Mike&quot;]</pre><p>Now I want new users array with new user</p><pre>var arrUsers = [&quot;Pawan&quot;, &quot;John&quot;, &quot;Mike&quot;]<br>let newUser = &quot;Brock&quot; // New user<br>let arrNewUsers = arrUsers + [newUser]</pre><p>So I created new user variable by appending into new users array by using [], but we have <strong>CollectionOfOne </strong>which can help us here to do it in better and cleaner way</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*co1GOXtEGjryIZBO2lA2QQ.gif" /><figcaption>Source: <a href="https://giphy.com/">https://giphy.com</a></figcaption></figure><pre>var arrUsers = [&quot;Pawan&quot;, &quot;John&quot;, &quot;Mike&quot;]<br>let newUser = &quot;Brock&quot; // New user<br>let arrNewUsers = arrUsers + CollectionOfOne(newUser)</pre><p>This is possible because <strong>CollectionOfOne </strong>confirms to collection protocol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*HtcciOI02pY1Qv8DW96tyg.png" /></figure><p><strong>For more visit: </strong><a href="https://ioslifee.blogspot.com/"><strong>https://ioslifee.blogspot.com</strong></a></p><p><em>Thanks for reading, Happy Coding 💻</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=776591e8e8e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Merge policy in Core Data]]></title>
            <link>https://manjani-pavan.medium.com/merge-policy-in-core-data-74f1cb0547ea?source=rss-1306b6bf47c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/74f1cb0547ea</guid>
            <category><![CDATA[mergepolicy]]></category>
            <category><![CDATA[core-data]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Pawan Manjani]]></dc:creator>
            <pubDate>Fri, 21 Apr 2023 17:53:09 GMT</pubDate>
            <atom:updated>2023-04-21T18:03:53.117Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*TqKecfDo-ekSAanr5lFHuw.png" /></figure><p>First question how to prevent duplicate entries in core data?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*m-u0i5sZYIPif-mLzC9GYg.gif" /><figcaption>Source: <a href="https://giphy.com/">https://giphy.com</a></figcaption></figure><p>Constraints, by giving constraints to our entity we can prevent duplicate entries in core data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDUn9rWPYYTE4nYD79yKBw.png" /></figure><p>We can set multiple attribute by comma separated(it’s case sensitive). In my case I have set only for name attribute.</p><p>So now if you try to insert any duplicate data it will throw an error.</p><p>But what if we want to replace the existing data with the new one?</p><p>here <strong>merge policy</strong> will help here us</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*WU9g1UwouyoctUqrkovjvg.gif" /><figcaption>Source: <a href="https://giphy.com/">https://giphy.com</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-l8uO1XH9iM-BA_3X3SAuQ.png" /></figure><p>We have to set mergePolicy to our Persistent Container(it has responsible for executing queries on the store)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*1AZUMp5zU8-JXq-HeacNHw.gif" /></figure><p>In above example if I’m trying to insert new data with same name then it’s replacing the old data with new one but it’s not inserting new data or throwing an error.</p><p>But also we have total <strong>5 types of merge policy:</strong></p><p><strong>1.</strong> <strong>NSMergeByPropertyObjectTrumpMergePolicy</strong> — it takes whatever was in the object context(the data store changes will be discarded for the changed properties).</p><p><strong>2.</strong> <strong>NSMergeByPropertyStoreTrumpMergePolicy</strong> — it takes whatever was in the store.</p><p><strong>3.</strong> <strong>NSErrorMergePolicy</strong> — it simply returns an error for each merge conflict, and is the default.</p><p><strong>4.</strong> <strong>NSOverwriteMergePolicy</strong> — it simply force all the changes in the object context into the data store.</p><p><strong>5.</strong> <strong>NSRollbackMergePolicy</strong> — it discards any object context changes that conflict with what’s in the data store. If you made a changes but that changes is not stored yet so that all changes which is not stored or changed that will be discarded.</p><p><strong>For more visit: </strong><a href="https://ioslifee.blogspot.com/"><strong>https://ioslifee.blogspot.com</strong></a></p><p><em>Thanks for reading, Happy Coding 💻</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74f1cb0547ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Import Specific Module in Swift]]></title>
            <link>https://manjani-pavan.medium.com/import-specific-module-in-swift-7d3a40c38bdc?source=rss-1306b6bf47c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d3a40c38bdc</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Pawan Manjani]]></dc:creator>
            <pubDate>Sun, 14 Aug 2022 15:38:55 GMT</pubDate>
            <atom:updated>2022-08-14T15:45:48.709Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*TKVojtFnZLy7F4B9L-dt9g.jpeg" /></figure><p>We use to import modules in our Swift file like:</p><pre><strong>import</strong> UIKit</pre><p>But what if I say we can import specific modules in our file instead of importing the entire module</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*4QkDKX-yKw_fjXD6Xr0qKA.gif" /><figcaption><a href="https://giphy.com/">https://giphy.com</a></figcaption></figure><p>Yes we can like below:</p><pre>import UIKit.UIViewController</pre><p>Let me give you more example</p><p>Suppose you have created the framework <strong>MyFramework</strong> and there you have enum, struct, class, etc but you want to use only enum from that Framework then you can import like:</p><pre><strong>import</strong> <strong>enum</strong> MyFramework.FlowType</pre><blockquote><strong>Note: Make sure that enum should be public</strong></blockquote><p>If you try to use struct from same Framework then compiler will throw error like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*eVrB9sTz5l8DMT47W2wvzQ.png" /></figure><p>If you want to use struct from Framework then you have to import like below:</p><pre><strong>import</strong> <strong>struct</strong> MyFramework.MyStruct</pre><p><strong>For more visit: </strong><a href="https://ioslifee.blogspot.com/"><strong>https://ioslifee.blogspot.com</strong></a></p><p><em>Thanks for reading, Happy Coding 💻</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d3a40c38bdc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Break outer loop in Swift]]></title>
            <link>https://manjani-pavan.medium.com/break-outer-loop-in-swift-a6f991cc1749?source=rss-1306b6bf47c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6f991cc1749</guid>
            <category><![CDATA[multipleloop]]></category>
            <category><![CDATA[for-loop]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Pawan Manjani]]></dc:creator>
            <pubDate>Sat, 04 Jun 2022 10:55:40 GMT</pubDate>
            <atom:updated>2022-06-04T10:55:40.489Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*ND2d6CvH-Cz0dp5I_tYalQ.png" /></figure><p>Many times we have to use multiple loops in our project like below: -</p><pre><strong>for</strong> i <strong>in</strong> 1...10 {</pre><pre> print (&quot;loop 1 at \(i)&quot;)</pre><pre><strong> for</strong> j <strong>in</strong> 1...5 {</pre><pre><strong>  if</strong> i == 5 {</pre><pre><strong>   break</strong></pre><pre>  }</pre><pre> print (&quot;loop 2 at \(j)&quot;)</pre><pre> }</pre><pre>}</pre><p>Now case is that I want to break outer loop when my condition got satisfied</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*F3jB9uNRl08Fyy4_-AtfsQ.gif" /><figcaption>Source: <a href="https://giphy.com/">https://giphy.com</a></figcaption></figure><p>But here <strong>Labeled Statement<em>s</em></strong> can help us in this case like below: -</p><pre><strong>outerLoop</strong>: <strong>for</strong> i <strong>in</strong> 1...10 { // We provided a name to loop here</pre><pre> print (&quot;loop 1 at \(i)&quot;)</pre><pre><strong> for</strong> j <strong>in</strong> 1...5 {</pre><pre><strong>  if</strong> i == 5 {</pre><pre><strong>   break</strong> <strong>outerLoop // We break specific loop here</strong></pre><pre>  }</pre><pre> print (&quot;loop 2 at \(j)&quot;)</pre><pre> }</pre><pre>}</pre><p>we added a label to the outer loop so we can break out of both loops at once.</p><p>So this is the best way to handle multiple loops in Swift, and we can able to break or continue the correct loop.</p><p><strong><em>Note</em>: We can give any name to outer loop</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*6TYqMppsXPc0yo95nyisPA.gif" /><figcaption>Source: <a href="https://giphy.com/">https://giphy.com</a></figcaption></figure><p><strong>For more visit: </strong><a href="https://ioslifee.blogspot.com/"><strong>https://ioslifee.blogspot.com</strong></a></p><p><em>Thanks for reading, Happy Coding 💻</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6f991cc1749" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>