<?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 Randhir Raj on Medium]]></title>
        <description><![CDATA[Stories by Randhir Raj on Medium]]></description>
        <link>https://medium.com/@randhirraj3130?source=rss-108e3839b9da------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1Li_SlaVPj6abTmX2jdV-w.png</url>
            <title>Stories by Randhir Raj on Medium</title>
            <link>https://medium.com/@randhirraj3130?source=rss-108e3839b9da------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 05:25:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@randhirraj3130/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[iOS Interview Questions for MNC’s (Infosys,cognizent , HCL, Wipro, Capgemini)]]></title>
            <link>https://medium.com/@randhirraj3130/ios-interview-questions-for-mncs-infosys-cognizent-hcl-wipro-capgemini-2a468d0b56ca?source=rss-108e3839b9da------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a468d0b56ca</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Randhir Raj]]></dc:creator>
            <pubDate>Thu, 07 Jul 2022 18:56:02 GMT</pubDate>
            <atom:updated>2022-07-08T05:28:19.378Z</atom:updated>
            <content:encoded><![CDATA[<h3>iOS Interview Questions for MNC’s (Infosys,cognizent , HCL, Wipro)</h3><p><strong>Autolayout and UI design Questions</strong></p><ol><li>difference between UX and UI?</li><li>Content hugging and compression resistance</li><li>What is Autolayout</li><li>Auto layout properties — Equal | Less Than or Equal | Greater Than or Equal</li><li>how to create that button through programmatically explain?</li><li>how many ways u give autolayouts?</li><li>What is multiplier?</li><li>How to create UI programatically? NSLayoutContraints, Anchor, Visual constraint?</li><li>What are the advantages of using SwiftUI over UIKIt?</li><li>What are different size classes available in iOS?</li><li>What is difference between content hugging &amp; content compression resistance priorities?</li><li>What is Intrinsic content size?</li><li>left anchor and leading anchor</li><li>What is mean by properties attributes, differences between atomic, copy, retain ?</li><li>What is mean by @dynamic in objective-c ?</li><li>What is @implementation only</li><li>Stack view properties and how to manage spacing inside its child view</li></ol><h4><strong>Network Security Questions</strong></h4><ol><li>What is mean by SSL pinning? How many ways to implement it? What is cross &amp; cons of each method? Which delegate function will perform this SSL pining handshake ?</li><li>What is Codable, Decodable, Encodable</li><li>Ways of data security in iOS</li><li>How to achieve app security in iOS? In terms of data in transit &amp; data at rest?</li><li>How to store data securely in iOS device? Keychain, Files with cryptography techniques.</li><li>Security in ios, multiple security option available</li><li>Coding and Decoding</li><li>Encryption algorithms</li></ol><h4><strong>Coading Architecture and design pattern</strong></h4><ol><li>Design Patterns:- MVC , MVVM, VIP,VIPER</li><li>What is POP and how it is different than OOP</li><li>In MVVM how will you create bidirectional communication?</li><li>What is mean by KVC &amp; KVO ? How to achieve it in swift?</li><li>Explain SOLID principles?</li><li>Explain design patterns with single liner explanation of each?</li><li>Vip clean architecture</li></ol><h4><strong>Version Control System</strong></h4><ol><li>Git and its steps to use</li><li>Git pull vs fetch?</li><li>What is ABI.</li><li>Explain basic git commands? What is difference between git fetch &amp; git pull command ? What is difference between git merge &amp; git rebase?</li></ol><h4><strong>Local Database</strong></h4><ol><li>What is core data?</li><li>Explain core data stack &amp; responsibility of each component in core data stack?</li><li>What are deletion rules in core data? How to achieve multithreading in core data?</li><li>What is SQLite?</li><li>What is difference between core data &amp; SQLite ?</li><li>Why not used API calls in this project in place of Sql Lite DB</li><li>How to share data between 2 apps</li><li>How do we keep track that latest data has been updated in the local SQLlite DB.</li><li>Keychain and how to store data in it (syntax)</li><li>How to make sure that the database is not accessible to anyone outside the application</li><li>Diff between userdefaults and keychain</li></ol><p><strong>Multithreading</strong></p><ol><li>How to achieve multithreading in iOS? What are different types of queues in GCD?, OperationQueue, NSThread, Thread Lock?</li><li>What are advantages of OperationQueue over GCD?</li><li>What is mean by quality of service?</li><li>DispatchQueue vs OperationQueue</li><li>What is difference between static dispatch &amp; dynamic dispatch?</li><li>Types of QOS in dispatchquque?</li><li>sync and async blocks</li></ol><p><strong>Delegate ,Protocol and closure</strong></p><ol><li>What is Protocol?</li><li>What is Closure?</li><li>What is delegate?</li><li>Difference between protocol and inheritance.</li><li>Can Struct and enum adopt the protocols?</li><li>How swift protocol are different from objective c protocol</li><li>What is difference between escaping &amp; non escaping closure?</li><li>When you implement function in protocol extention what happens?</li><li>What is protocol/Delegate in swift? Write a code to declare a protocol?</li><li>What is Protocol extension?</li><li>Why Protocols used in swift but not in Objective-C?</li><li>What is Protocol extension? Explain how we Restrict the protocol extension to a particular class only?</li><li>Different inbuilt protocol in swift ?</li><li>delegate vs Notification centre</li><li>what are Closures? What are the types of closure?</li><li>Notification and delegation difference</li><li>How can we return value in auto Closures?</li><li>How to make an optional method in swift protocol? What is use of protocol extension?</li></ol><h4><strong>Unit Testing</strong></h4><ol><li>Unit Testing with example</li><li>XCTest framework</li><li>How to write Unit Test Cases in XCode, where we can get code coverage option in XCode</li><li>What is mean by TDD? What is difference between TDD &amp; BDD?</li><li>Do you have experience on BDD? UI testing? What is mean by snapshot testing?</li></ol><h4><strong>Class , Structure and enum</strong></h4><ol><li>Difference between Class and Struct.</li><li>How to use generics with Enum</li><li>What is Enumeration? What are the different enumerations we are using in Swift’s name at least 10?</li><li>How to adopt 2 or more protocols to class in single line, ie.. Without comma?</li><li>What is enum and it’s associated value</li><li>Generics and associated type</li><li>what is singleton class</li><li>What’s need to use convenience initialisers in swift</li><li>What is difference between enum &amp; struct</li><li>static vs class variable?</li><li>Strong reference cycle and how to avoid it with practical example</li><li>Why stack is faster? Why not Heap memory.</li><li>Can subclass override a protocol function from super class which is adopted the protocol? Ex: there is a Protocol called proA{} and classA{} and classB{}. classA adopted the protocol proA and classB inherited from classA. Now can you override any protocol function in classB ?</li><li>What are different access level available in swift? What is default access level in swift? What is difference between open &amp; public?</li><li>How to pass the parameter as a reference type to other function?</li><li>can we inherit from structs?</li><li>What is the Associated type? What is the Associated type for protocol? Associated type for enumeration?</li><li>What is Equatable ?</li><li>Types of initializer</li><li>Inout parameters</li><li>Mutating Keyword.</li><li>why struct is lightweight?</li></ol><h4><strong>Networking Classs</strong></h4><ol><li>How to achieve networking in iOS ? What are different types of tasks we can create using URLSession?</li><li>What is difference between URLSession &amp; NSURLConnection?</li><li>What are different delegate methods of URLSession?</li><li>What is WebSocket? How do you implement it in your project?</li><li>difference between get and post?</li><li>explain rest API?</li><li>http methods</li><li>Difference between POST and PUT</li><li>what are the types of webservices(REST &amp; SOAP)?</li></ol><h4><strong>Null ,error and memory management</strong></h4><ol><li>Error Handling in Swift ?</li><li>what is optional chaining &amp; optional binding</li><li>Guard and if statement difference</li><li>What is mean by ARC? Explain in detail with an example?</li><li>What is mean by capture list? What is difference between weak &amp; unowned ? When to use weak &amp; when to use unowned with proper example?</li><li>Error Handling in swift? difference between Throws and throw?</li><li>Lazy computed properties</li><li>strong weak</li><li>What is difference between stored properties &amp; computed properties?</li><li>How to troubleshoot an app crash? OR How to troubleshoot an app memory leakage? What tools are you using for it?</li><li>How to detect memory leak</li><li>How to extract value from optional variable</li><li>What is optional and how to unwrap that value?</li><li>How to user Instruments</li><li>ARC</li><li>Difference between weak and unowned keywords</li><li>why are you using Extensions?</li><li>Difference between try , try? And try!</li></ol><h4><strong>iOS Application Life cycle</strong></h4><ol><li>Explain ViewLife cycle methods? Their sequence of execution?</li><li>Explain E2E iOS code signing process? (Uploading app on app center process)?</li><li>What are different types of iOS Application States?</li><li>Dynamic framework , have you developed one?</li><li>explain static library?</li></ol><h4><strong>DeepLinking and dependency injection</strong></h4><ol><li>When opening app from deeplinking how to pass the data?</li><li>Dependency injection</li><li>What is deeplinking and setup process?</li></ol><p><strong>Access Modifier and Higher order function</strong></p><ol><li>What is difference between flatmap &amp; compact map ?</li><li>Private vs fileprivate</li><li>Explain access modifiers? How we can Define the Module in swift?</li><li>what are higher order function in swift</li></ol><h4><strong>Swift , objective c and OOPS</strong></h4><ol><li>Explain OOP’s concepts in details?</li><li>difference between swift 5.0 and swift 5.3 version?</li><li>Why swift is better than objective C</li><li>Oops concept</li><li>Swift latest version Features.</li><li>Pros and cons of swift and Objective C</li><li>What is Rx-Swift? What is mean by Observable sequences? What is mean by subjects in Rx-Swift?</li><li>About Swift &amp; features</li><li>Inheritance type</li><li>diff between abstraction and encapsulation</li><li>What is Keypath in swift?</li><li>Type of properties in swift</li><li>what is tuple</li><li>what is localization ?</li><li>Static keyword</li><li>defer keyword and multiple defer statement</li><li>Method Swizzling</li><li>What is Whitelisting?</li></ol><h4><strong>Push Notification and generics</strong></h4><ol><li>Explain Pushnotification setup process</li><li>What is generics? Where you use the generics in real-time?</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a468d0b56ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Final Keyword in swift]]></title>
            <link>https://medium.com/@randhirraj3130/final-keyword-in-swift-862fa835dff7?source=rss-108e3839b9da------2</link>
            <guid isPermaLink="false">https://medium.com/p/862fa835dff7</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[final-keyword]]></category>
            <dc:creator><![CDATA[Randhir Raj]]></dc:creator>
            <pubDate>Thu, 07 Jul 2022 11:12:52 GMT</pubDate>
            <atom:updated>2022-07-07T11:17:21.965Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>You can prevent a method, property, or subscript from being overridden by marking it as <strong><em>final</em></strong>.</li><li>Swift gives us a <strong>final</strong> keyword just for this purpose: when you declare a class as being final, no other class can inherit from it.</li></ul><blockquote>Final class Test {</blockquote><blockquote>var dob = “16/10/1993”</blockquote><blockquote>}</blockquote><blockquote>class Test2 : Test {</blockquote><blockquote>func getName() -&gt; String {</blockquote><blockquote>return “randhir DOB is \(dob)”</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><blockquote>print(Test2().getName())</blockquote><h4><strong>Most frequently asked Interview Questions</strong></h4><ol><li>What is final keyword with example.</li></ol><p><em>Thanks for reading…… </em><a href="https://randhirkushwaha3130.github.io/"><em>Randhir Raj</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=862fa835dff7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Access levels in iOS(Swift)]]></title>
            <link>https://medium.com/@randhirraj3130/access-levels-in-ios-swift-947509f9a37d?source=rss-108e3839b9da------2</link>
            <guid isPermaLink="false">https://medium.com/p/947509f9a37d</guid>
            <category><![CDATA[access-control-systems]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Randhir Raj]]></dc:creator>
            <pubDate>Thu, 07 Jul 2022 10:18:10 GMT</pubDate>
            <atom:updated>2022-07-07T11:19:00.339Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>Access control restricts access to parts of your code from code in other source files and modules. This feature enables you to hide the implementation details of your code, and to specify a preferred interface through which that code can be accessed and used.</li><li>Swift provides five different <em>access levels</em> for entities within your code. These access levels are relative to the source file in which an entity is defined, and also relative to the module that source file belongs to.</li></ul><h3>1. Open</h3><ul><li>open classes and class members can be subclassed and overridden both within and outside the defining module (target/framework).</li></ul><h3><strong>2. Public</strong></h3><ul><li>public classes and class members can only be subclassed and overridden within the defining module (target/framework).</li></ul><blockquote><strong>//First.framework — A.swift</strong></blockquote><blockquote>open class A {}</blockquote><blockquote><strong>//First.framework — B.swift</strong></blockquote><blockquote>public class B: A {} // ok</blockquote><blockquote><strong>//Second.framework — C.swift</strong></blockquote><blockquote>import First</blockquote><blockquote>internal class C: A {} // ok</blockquote><blockquote><strong>//Second.framework — D.swift</strong></blockquote><blockquote>import First</blockquote><blockquote>internal class D: B {} // error: B cannot be subclassed</blockquote><p><strong>Open vs Public</strong></p><p>Like open access level, public access level enable an entity to be used outside the defining module (target). But open access level allows us to subclass it from another module where in public access level, we can only subclass or overridde it from within the module it is defined.</p><h3>3. Private:</h3><ul><li>Restricts the use of an entity to its enclosing declaration.</li><li>You typically use <strong><em>private</em></strong> access to hide the implementation details of a specific piece of functionality when those details are used only within a single declaration.</li><li><strong><em>private</em></strong> means an entity that cannot be accessed anywhere except for the enclosing type, such as a class.</li></ul><p><strong>Example</strong>:-</p><blockquote><em>class TestPrivate {</em></blockquote><blockquote><em>private var number1: Int = 10</em></blockquote><blockquote><em>}</em></blockquote><blockquote><em>let ex = TestPrivate()</em></blockquote><blockquote><em>print(ex.number1) // Error</em></blockquote><h3>4. FilePrivate:</h3><ul><li>Restricts the use of an entity to its defining source file only.</li><li>You typically use <strong>fileprivate</strong> access to hide the implementation details of a specific piece of functionality when those details are used within an entire file.</li></ul><p><strong>Example</strong>:-</p><blockquote><em>class TestFilePrivate {</em></blockquote><blockquote><em>fileprivate var number1: Int = 10</em></blockquote><blockquote><em>}</em></blockquote><blockquote><em>let ex = TestFilePrivate()</em></blockquote><blockquote><em>print(ex.number1) // 10</em></blockquote><h3>5. Internal:</h3><ul><li>Enables an entity to be used within the defining module (target).</li><li>You typically use <strong><em>internal </em></strong>access when defining an app’s or a framework’s internal structure.</li><li>Default access specifier in swift is <strong><em>internal</em>,</strong></li></ul><p><strong>Example:</strong></p><blockquote><strong>// First.framework — A.swift</strong></blockquote><blockquote>internal struct A {</blockquote><blockquote>fileprivate static let x: Int</blockquote><blockquote>}</blockquote><blockquote><strong>// First.framework — A.swift</strong></blockquote><blockquote>internal struct A {}</blockquote><blockquote><strong>// First.framework — B.swift</strong></blockquote><blockquote>A() // ok</blockquote><blockquote><strong>// Second.framework — C.swift</strong></blockquote><blockquote>import First</blockquote><blockquote>A() // error: A is unavailable</blockquote><p><em>************* Thanks for reading…….. </em><a href="https://randhirkushwaha3130.github.io/"><em>Randhir Raj</em></a><em> *************</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=947509f9a37d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Factory Design Pattern in Sw]]></title>
            <link>https://medium.com/@randhirraj3130/factory-design-pattern-in-sw-57c466d74f2b?source=rss-108e3839b9da------2</link>
            <guid isPermaLink="false">https://medium.com/p/57c466d74f2b</guid>
            <category><![CDATA[factory-pattern]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[objective-c]]></category>
            <dc:creator><![CDATA[Randhir Raj]]></dc:creator>
            <pubDate>Wed, 29 Jun 2022 08:34:11 GMT</pubDate>
            <atom:updated>2022-07-07T11:20:41.136Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Factory Design Pattern in iOS(Swift)</strong></h3><ul><li>The factory pattern is a way to encapsulate the implementation details of creating objects, which adheres to a common base class or interface.</li><li>The factory pattern separates the implementation details of creating objects from the common interface that allows users to generically use the object. Let’s consider an example to make this idea more concrete.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*HdldCEUqLc83a3jXEcwu3g.png" /></figure><h4><strong>Example:-</strong></h4><p><strong>Step 1:-</strong> First, we will create the interface (or rather, protocol) that we will use to send our customized emails to our potential clients with information on the type of job they are seeking.</p><pre>protocol JobProtocol {</pre><pre>func sendResume()-&gt;String</pre><pre>}</pre><pre>Let’s also add a struct for the Contact object.</pre><pre>struct ContactDetails {</pre><pre>var name: String</pre><pre>var email: String</pre><pre>var job: Job</pre><pre>var desiredSal: Double</pre><pre>enum Job {</pre><pre>case iOS</pre><pre>case Android</pre><pre>case Web</pre><pre>case QA</pre><pre>case Product_Owner</pre><pre>}</pre><pre>}</pre><p><strong>Step 2:</strong>- Next, we will create several template objects that adhere to the <em>JobProtocol</em>. We need templates to send to mobile developers, web developers, QA/ Testing, and product owners. We want to hide the details of these objects from clients and only expose the interface for use. What makes this pattern really useful is that each class is in charge of its implementation and can do anything as long as it adheres to the protocol. It can be used in a generic way by a client that only knows about the protocol.</p><h4>1. iOS Job Seeker Details:-</h4><blockquote>struct iOSJobSeekerDetails: JobProtocol{</blockquote><blockquote>var contactDetails: ContactDetails</blockquote><blockquote>init(contact: ContactDetails){</blockquote><blockquote>self.contactDetails = contact</blockquote><blockquote>}</blockquote><blockquote>func sendResume()-&gt;String{</blockquote><blockquote>return “Dear \(contact.name), this is the best time to be an iOS developer! Send me you’re resume today! I have job opportunities that pay \(contact.desiredSal).”</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><h4>2. Android Job Seeker Details:-</h4><blockquote>struct AndroidJobSeekerDetails: JobProtocol{</blockquote><blockquote>var contactDetails: ContactDetails</blockquote><blockquote>init(contact: ContactDetails){</blockquote><blockquote>self.contactDetails = contact</blockquote><blockquote>}</blockquote><blockquote>func sendResume()-&gt;String{</blockquote><blockquote>return “Dear \(contact.name), this is as decent time to be an Android developer! Send me you’re resume today! I have job opportunities that pay close to the \(contact.desiredSal) you are looking for”</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><h4>3. WEB Job Seeker Details:-</h4><blockquote>struct WebJobSeekerDetails: JobProtocol{</blockquote><blockquote>var contactDetails: ContactDetails</blockquote><blockquote>init(contact: ContactDetails){</blockquote><blockquote>self.contactDetails = contact</blockquote><blockquote>}</blockquote><blockquote>func sendResume()-&gt;String{</blockquote><blockquote>return “Dear \(contact.name), Send me you’re resume today! I have job opportunities for you.”</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><h4>4. QA Job Seeker Details:-</h4><blockquote>struct QAJobSeekerDetails: JobProtocol{</blockquote><blockquote>var contactDetails: ContactDetails</blockquote><blockquote>init(contact: ContactDetails){</blockquote><blockquote>self.contactDetails = contact</blockquote><blockquote>}</blockquote><blockquote>func sendResume()-&gt;String{</blockquote><blockquote>return “Dear \(contact.name), The market is tough but the code is still buggy! Good news for you because I know the best companies for buggy code and they need you!”</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><h4>5. Product Owner Job Seeker Details:-</h4><blockquote>struct ProductOwnerJobSeekerDetails: JobProtocol{</blockquote><blockquote>var contactDetails: ContactDetails</blockquote><blockquote>init(contact: ContactDetails){</blockquote><blockquote>self.contactDetails = contact</blockquote><blockquote>}</blockquote><blockquote>func sendResume()-&gt;String{</blockquote><blockquote>return “Dear \(contact.name), Times are still good to be in development. Maybe you should consider learning to code or going back to code. If we can cut your desired salary of \(contact.desiredSal) in half, I should be able to place you as a contract to hire. Send me your resume!”</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><p><strong>Step 3:-</strong> Our next step is to create the actual factory that our client will use to get a concrete object that adheres to our protocol. The factory object in our case has just one method to return the job seeker object that adheres to the <strong><em>JobProtocol</em></strong> based on a <em>ContactDetails</em> object that is passed in as a parameter to the function.\</p><p><strong><em>Job Seeker Details:-</em></strong></p><blockquote>struct JobFactory{</blockquote><blockquote>static func getJobSeeker(contact: ContactDetails)-&gt;JobProtocol {</blockquote><blockquote>switch contact.job {</blockquote><blockquote>case .iOS:</blockquote><blockquote>return iOSJobSeekerDetails(contact: contact)</blockquote><blockquote>case .Android:</blockquote><blockquote>return AndroidJobSeekerDetails(contact: contact)</blockquote><blockquote>case .Web:</blockquote><blockquote>return WebJobSeekerDetails(contact: contact)</blockquote><blockquote>case .QA:</blockquote><blockquote>return QAJobSeekerDetails(contact: contact)</blockquote><blockquote>case .Product_Owner:</blockquote><blockquote>return ProductOwnerJobSeekerDetails(contact: contact)</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><h4>Pros and Cons</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*jrp8dHKLVYP1tDmJsQiCyA.png" /></figure><p><em>************* Thanks for reading…….. </em><a href="https://randhirkushwaha3130.github.io/"><em>Randhir Raj</em></a><em> *************</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57c466d74f2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Facade Design Pattern in iOS(Swift)]]></title>
            <link>https://medium.com/@randhirraj3130/facade-design-pattern-in-ios-swift-1df0c0c5e850?source=rss-108e3839b9da------2</link>
            <guid isPermaLink="false">https://medium.com/p/1df0c0c5e850</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[facade-pattern]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Randhir Raj]]></dc:creator>
            <pubDate>Wed, 29 Jun 2022 06:55:04 GMT</pubDate>
            <atom:updated>2022-07-07T11:21:11.314Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>The Facade design pattern provides a single interface to a complex subsystem. Instead of exposing the user to a set of classes and their APIs, you only expose one simple unified API.</li><li>The user of the API is completely unaware of the complexity that lies beneath. This pattern is ideal when working with a large number of classes, particularly when they are complicated to use or difficult to understand.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*PMbydeJrZBfEF0jXk3ydwg.png" /></figure><ul><li>The Facade pattern decouples the code that uses the system from the interface and implementation of the classes you’re hiding; it also reduces dependencies of outside code on the inner workings of your subsystem. This is also useful if the classes under the facade are likely to change, as the facade class can retain the same API while things change behind the scenes.</li></ul><h4><strong>How to Use the Facade Pattern</strong></h4><p>Currently you have PersistencyManager to save the album data locally and HTTPClient to handle the remote communication. The other classes in your project should not be aware of this logic, as they will be hiding behind the facade of Webservice.</p><p>To implement this pattern, only Webservice should hold instances of PersistencyManager and HTTPClient. Then, Webservice will expose a simple API to access those services.</p><p><strong>The design looks like the following:</strong></p><pre>class Webservice{<br>private let persistencyManager = PersistencyManager()</pre><pre>private let httpClient = HTTPClient()</pre><pre>private let isOnline = false<br></pre><pre>func getAlbums() -&gt; [Album] {</pre><pre>return persistencyManager.getAlbums()</pre><pre>}</pre><pre>func addAlbum(_ album: Album, at index: Int) {</pre><pre>persistencyManager.addAlbum(album, at: index)</pre><pre>if isOnline {</pre><pre>httpClient.postRequest(&quot;/api/addAlbum&quot;, body: album.description)</pre><pre>}</pre><pre>}</pre><pre>func deleteAlbum(at index: Int) {</pre><pre>persistencyManager.deleteAlbum(at: index)</pre><pre>if isOnline {</pre><pre>httpClient.postRequest(&quot;/api/deleteAlbum&quot;, body: &quot;\(index)&quot;)</pre><pre>}</pre><pre>}<br>}</pre><h4>Advantage of Facade Pattern</h4><ul><li>It shields the clients from the complexities of the sub-system components.</li><li>It promotes loose coupling between subsystems and its clients.</li></ul><p><em>************* Thanks for reading…….. </em><a href="https://randhirkushwaha3130.github.io/"><em>Randhir Raj</em></a><em> *************</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1df0c0c5e850" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Singleton Pattern in iOS(Swift)]]></title>
            <link>https://medium.com/@randhirraj3130/singleton-pattern-in-ios-swift-4e8c0b0f6f4d?source=rss-108e3839b9da------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e8c0b0f6f4d</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[singleton-design-pattern]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Randhir Raj]]></dc:creator>
            <pubDate>Mon, 27 Jun 2022 07:34:29 GMT</pubDate>
            <atom:updated>2022-07-07T11:21:41.557Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>The Singleton design pattern ensures that only one instance exists for a given class and that there’s a global access point to that instance.</li><li>It usually uses lazy loading to create the single instance when it’s needed the first time.</li></ul><p><strong>Note:</strong> Apple uses this approach a lot.</p><p><strong>Example</strong>: UserDefaults.standard, UIApplication.shared, UIScreen.main, FileManager.default all return a Singleton object.</p><h4><strong>How to Use the Singleton Pattern</strong></h4><p>To ensure there is only one instance of your singleton, you must make it impossible for anyone else to make an instance. Swift allows you to do this by marking the initializers as private. You can then add a static property for the shared instance, which is initialized inside the class.</p><pre>final class SingletonTest {</pre><pre>// 1</pre><pre>static let shared = SingletonTest()</pre><pre>// 2</pre><pre>private init(){}</pre><pre>}</pre><pre>}</pre><h4><strong>Disadvantage of Singleton:-</strong></h4><ul><li>One of the main disadvantages of singletons is that they make <strong>unit testing</strong> very hard. They introduce global state to the application. The problem is that you cannot completely isolate classes dependent on singletons. When you are trying to test such a class, you inevitably test the Singleton as well. When unit testing, you want the class to be as loosely coupled with other classes as possible and all the dependencies of the class should be ideally provided externally (either by constructor or setters), so they can be easily mocked. Unfortunately, that is not possible with singletons as they introduce tight coupling and the class retrieves the instance on its own. But it gets even worse. The global state of stateful singletons is preserved between test cases.</li><li>It is static so memory will not be freeze until app will killed. It has it’s own creation time and its own lifecycle.</li><li>Singletons create hidden dependencies. As the Singleton is readily available throughout the code base, it can be overused. Moreover, since its reference is not completely transparent while passing to different methods, it becomes difficult to track. (To solve that we should pass singleton object variable as parameter and this way is called dependency injection).</li></ul><p><em>************* Thanks for reading…….. </em><a href="https://randhirkushwaha3130.github.io/"><em>Randhir Raj</em></a><em> *************</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e8c0b0f6f4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Swift Architecture (VIP)]]></title>
            <link>https://medium.com/@randhirraj3130/clean-swift-architectur-vip-60268577b964?source=rss-108e3839b9da------2</link>
            <guid isPermaLink="false">https://medium.com/p/60268577b964</guid>
            <category><![CDATA[clean-swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Randhir Raj]]></dc:creator>
            <pubDate>Fri, 24 Jun 2022 06:08:41 GMT</pubDate>
            <atom:updated>2022-07-07T11:22:44.240Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>VIP is an architectural pattern like MVC, MVP or MVVM. Its main difference is the clear logic separation between its components.</li><li>VIP was created to fix MVC, or Massive View Controllers, a common problem in <strong><em>UIKit</em></strong> apps where View Controllers become the main object where code is kept and they become Massive in that most if not all of your logic is kept within them.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*v8gpPM5GEEhNrQrwAzWSHw.png" /></figure><ul><li>The VIP pattern is a <strong><em>unidirectional</em></strong> architectural pattern.</li><li>Each letter in VIP stands for one component: <strong>View</strong>, <strong>Interactor</strong> and <strong>Presenter</strong>.</li><li>The <strong>View</strong> is your app’s UI. This corresponds to a SwiftUI View. It sends requests to the interactor every time the user interacts with the UI.</li><li>The <strong>Interactor</strong> handles your app’s business logic, such as fetching data from the network or saving data in a database. When the view requests something, the interactor does the processing and sends the result as a response to the presenter.</li><li>The <strong>Presenter</strong> handles the presentation logic. It formats the received data into view models suitable for display and then passes it to the view.</li></ul><h4>Structuring Your Files in Xcode</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*Ueh5ynHyDU_kIUsI0Xjf8w.png" /></figure><h3>VIP Components</h3><h4>1. View Controller</h4><ul><li>Defines a scene and contains a view or views.</li><li>Keeps instances of the interactor and router.</li><li>Passes the actions from views to the interactor (output) and takes the presenter actions as input.</li></ul><blockquote>protocol LoginSceneVCInput: AnyObject {<br> func showLogingSuccess(fullUserName: String)<br> func showLogingFailure(message: String)<br> }<br> <br> protocol LoginSceneVCOutput: AnyObject {<br> func tryToLogIn()<br> }<br> <br> final class LoginSceneVC: UIViewController {<br> var interactor: LoginSceneInteractorInput?<br> var router: LoginSceneRoutingLogic?<br> <br> private var loginButton: UIButton = {…}()<br> }<br> <br> private extension LoginSceneVC {<br> @objc func loginButtonAction() {<br> interactor?.tryToLogIn()<br> }<br> }<br> <br> extension LoginSceneVC: LoginSceneVCInput {<br> func showLogingSuccess(fullUserName: String) {<br> router?.showLoginSuccess()<br> }<br> <br> func showLogingFailure(message: String) {<br> router?.showLogingFailure(message: message)<br> }<br> }</blockquote><h4>2. Interactor</h4><ul><li>Contains a Scene’s business logic.</li><li>Keeps a reference to the presenter.</li><li>Runs actions on workers based on input (from the View Controller), triggers and passes the output to the presenter.</li><li>The interactor should never import the UIKit.</li></ul><blockquote>typealias LoginSceneInteractorInput = LoginSceneVCOutput<br> <br> protocol LoginInteractorOutput: AnyObject {<br> func showLogingSuccess(user: CleanLoginUser)<br> func showLogingFailure(message: String)<br> }<br> <br> final class LoginSceneInteractor {<br> var presenter: LoginScenePresenterInput?<br> var authWorker: LoginSceneAuthLogic?<br> }<br> <br> extension LoginSceneInteractor: LoginSceneInteractorInput {<br> func tryToLogIn() {<br> authWorker?.makeAuth(completion: { result in<br> DispatchQueue.main.async { [weak self] in<br> switch result {<br> case .success(let data):<br> self?.presenter?.showLogingSuccess(user: data)<br> case .failure(let error):<br> self?.presenter?.showLogingFailure(message: error.localizedDescription)<br> }<br> }<br> })<br> }<br> }</blockquote><h4>Presenter</h4><ul><li>Keeps a weak reference to the view controller that is an output of the presenter.</li><li>After the interactor produces some results, it passes the response to the presenter. Next, the presenter marshals the response into view models suitable for display and then passes the view models back to the view controller for display to the user.</li></ul><blockquote>typealias LoginScenePresenterInput = LoginInteractorOutput<br> typealias LoginScenePresenterOutput = LoginSceneVCInput<br> <br> final class LoginScenePresenter {<br> weak var viewController: LoginScenePresenterOutput?<br> }<br> <br> extension LoginScenePresenter: LoginScenePresenterInput {<br> func showLogingFailure(message: String) {<br> viewController?.showLogingFailure(message: “”)<br> }<br> <br> func showLogingSuccess(user: CleanLoginUser) {<br> viewController?.showLogingSuccess(fullUserName: user.firstName + “ “ + user.lastName)<br> }<br> }</blockquote><h4>Router</h4><ul><li>Extracts this navigation logic out of the view controller.</li><li>Keeps a weak reference to the source (View Controller).</li></ul><blockquote>protocol LoginSceneRoutingLogic {</blockquote><blockquote>func showLoginSuccess()</blockquote><blockquote>func showLogingFailure(message: String)</blockquote><blockquote>}</blockquote><blockquote>final class LoginSceneRouter {</blockquote><blockquote>weak var source: UIViewController?</blockquote><blockquote>private let sceneFactory: SceneFactory</blockquote><blockquote>init(sceneFactory: SceneFactory) {</blockquote><blockquote>self.sceneFactory = sceneFactory</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><blockquote>extension LoginSceneRouter: LoginSceneRoutingLogic {</blockquote><blockquote>func showLogingFailure(message: String) {</blockquote><blockquote>source?.present(UIAlertController.failure(message), animated: true)</blockquote><blockquote>}</blockquote><blockquote>func showLoginSuccess() {</blockquote><blockquote>let scene = sceneFactory.makeLoginScene()</blockquote><blockquote>source?.navigationController?.pushViewController(scene, animated: true)</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><h4>Pros:-</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WRVYYsyx_OpIHkRogxHrhw.png" /></figure><p><strong>Cons:-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5fXuWwjF8m11iU0ge0O7dQ.png" /></figure><p><em>************* Thanks for reading…….. </em><a href="https://randhirkushwaha3130.github.io/"><em>Randhir Raj</em></a><em> *************</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60268577b964" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IOS app lifecycle]]></title>
            <link>https://medium.com/@randhirraj3130/ios-app-lifecycle-34a158c98744?source=rss-108e3839b9da------2</link>
            <guid isPermaLink="false">https://medium.com/p/34a158c98744</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[lifecycle]]></category>
            <dc:creator><![CDATA[Randhir Raj]]></dc:creator>
            <pubDate>Tue, 21 Jun 2022 10:50:17 GMT</pubDate>
            <atom:updated>2022-07-07T11:23:11.992Z</atom:updated>
            <content:encoded><![CDATA[<ul><li><strong><em>Not Running:</em></strong><em> the app is in a Not Running state when it is not yet launched or terminated by the system or user.</em></li><li><strong><em>Inactive:</em></strong><em> the app is in an inactive state when it is in the foreground but receiving events. In other words, we can say that it acts like a bridge state in which the app remains briefly when it transitions to a different state.</em></li><li><strong><em>Active:</em></strong><em> it is a normal mode for the app when it is in the foreground state and receiving all the user events.</em></li><li><strong><em>Background:</em></strong><em> the app transitions into the background state when the user taps on the home screen while using the application, or it requires some extra execution time. When the app is about to be suspended, then also transitions into this state for a small amount of time. In this state, the app remains in the background and executes the code.</em></li><li><strong><em>Suspended:</em></strong><em> in this state, the app remains in the background and doesn’t execute the code. The app is automatically moved to this state. In this state, the app remains in memory. However, the foreground apps are always given priority over suspended apps and can be purged any time without notice.</em></li></ul><h3><em>UIApplicationDelegate Lifecycle methods</em></h3><p><em>The UIApplicationDelegate contains certain app lifecycle methods that are notified when the app starts running. The UIApplicationDelegate methods are given below.</em></p><h4><strong><em>1. application: didFinishLaunchingWithOptions:-&gt; Bool:</em></strong></h4><p><em>When the application is launched initially, this method is called. We can do any initial setup for the application in this method like firebase configuration, user navigation, etc. The storyboard is loaded at this point, but we can maintain the state restoration.</em></p><blockquote><em>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool {</em></blockquote><blockquote><em>return true</em></blockquote><blockquote><em>}</em></blockquote><h4><strong><em>2. applicationWillEnterForeground:</em></strong></h4><p><em>this method is called after didFinishLaunchingWithOptions. It is also called when the application comes from background to foreground.</em></p><blockquote><em>func applicationWillResignActive(_ application: UIApplication) {</em></blockquote><blockquote><em>}</em></blockquote><h4><strong><em>3. applicationDidBecomeActive:</em></strong></h4><p><em>this method is called after applicationWillEnterForeground. If we need to perform any particular task when the app comes into the foreground, like font update, etc., then we can place the code in this method.</em></p><blockquote><em>func applicationDidEnterBackground(_ application: UIApplication) {</em></blockquote><blockquote><em>}</em></blockquote><h4><strong><em>4. applicationWillResignActive:</em></strong></h4><p><em>this method is notified when the application is about to become inactive. For example, the user receives a phone call; the user presses the home button, etc.).</em></p><blockquote><em>func applicationWillEnterForeground(_ application: UIApplication) {</em></blockquote><blockquote><em>}</em></blockquote><h4><strong><em>5. applicationDidEnterBackground:</em></strong></h4><p><em>this method is notified when the application goes into a background state after become inactive.</em></p><blockquote><em>func applicationDidBecomeActive(_ application: UIApplication) {</em></blockquote><blockquote><em>}</em></blockquote><p><strong><em>6. applicationWillTerminate:</em></strong><em> this method is called when the application is about to be finally terminated from memory. If we need to perform any final cleanups, then we can place the code in this method.</em></p><blockquote><em>func applicationWillTerminate(_ application: UIApplication) {</em></blockquote><blockquote><em>}</em></blockquote><h3>UIViewController Lifecycle methods</h3><h4><strong>1. loadView()</strong></h4><p>This is where subclasses should create their custom view hierarchy if they aren’t using a <a href="https://developer.apple.com/library/archive/documentation/General/Conceptual/DevPedia-CocoaCore/NibFile.html#//apple_ref/doc/uid/TP40008195-CH34-SW1">nib</a>. Should never be called directly.</p><p><strong>2. loadViewIfNeeded()</strong></p><p>Loads the view controller’s view if it has not already been set.</p><p><strong>3. viewDidLoad()</strong></p><p>Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set.</p><p><strong>4. viewWillAppear(_ animated: Bool)</strong></p><p>Called when the view is about to made visible. Default does nothing</p><p><strong>5. viewWillLayoutSubviews()</strong></p><p>Called just before the view controller’s view’s layoutSubviews method is invoked. Subclasses can implement as necessary. Default does nothing.</p><p><strong>6. viewDidLayoutSubviews()</strong></p><p>Called just after the view controller’s view’s layoutSubviews method is invoked. Subclasses can implement as necessary. Default does nothing.</p><p><strong>7. viewDidAppear(_ animated: Bool)</strong></p><p>Called when the view has been fully transitioned onto the screen. Default does nothing</p><p><strong>8. viewWillDisappear(_ animated: Bool)</strong></p><p>Called when the view is dismissed, covered or otherwise hidden. Default does nothing</p><p><strong>9. viewDidDisappear(_ animated: Bool</strong>)</p><p>Called after the view was dismissed, covered or otherwise hidden. Default does nothing</p><p><strong>10. viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)</strong></p><p>Called when the view is Transitioning.</p><p><strong>11. willMove(toParentViewController parent: UIViewController?)</strong></p><p><strong>12. didMove(toParentViewController parent: UIViewController?)</strong></p><p>These two methods are public for container subclasses to call when transitioning between child controllers. If they are overridden, the overrides should ensure to call the super.</p><p>The parent argument in both of these methods is nil when a child is being removed from its parent; otherwise it is equal to the new parent view controller.</p><p><strong>13. didReceiveMemoryWarning()</strong></p><p>Called when the parent application receives a memory warning. On iOS 6.0 it will no longer clear the view by default.</p><p><em>************* Thanks for reading…….. </em><a href="https://randhirkushwaha3130.github.io/"><em>Randhir Raj</em></a><em> *************</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34a158c98744" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automatic Reference Counting (ARC)]]></title>
            <link>https://medium.com/@randhirraj3130/automatic-reference-counting-arc-e0033fe03988?source=rss-108e3839b9da------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0033fe03988</guid>
            <category><![CDATA[cars]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Randhir Raj]]></dc:creator>
            <pubDate>Tue, 21 Jun 2022 06:12:32 GMT</pubDate>
            <atom:updated>2022-07-07T11:23:40.360Z</atom:updated>
            <content:encoded><![CDATA[<p>ARC is to track and manage the app’s memory usage. ARC automatically frees up the memory used by class instances when those instances are no longer needed.</p><h3>Memory allocations in swift (Heap and Stack Memory)</h3><ol><li><strong>Heap Memory</strong></li></ol><ul><li>Variables allocated on the heap have their memory allocated at run time, and accessing this memory is a bit slower, but the heap size is only limited by the size of virtual memory. Elements of the heap have no dependencies with each other and can always be accessed randomly at any time.</li></ul><p><strong>2. Stack Memory</strong></p><ul><li>Stack is used for static memory allocation and Heap for dynamic memory allocation, both stored in the computer’s RAM.</li><li>Variables allocated on the stack are stored directly to the memory, and access to this memory is very fast, and its allocation is determined when the program is compiled.</li></ul><h4><strong>How ARC Works?</strong></h4><p>Every time you create a new instance of a class, ARC allocates a chunk of memory to store information about that instance. This memory holds information about the type of the instance, together with the values of any stored properties associated with that instance.</p><h4><strong>1.</strong> <strong>strong reference example</strong></h4><blockquote>class Student {<br> var name: String<br> init(name: String) {<br> self.name = name<br> print(“\(name) is being initialized”)<br> } deinit {<br> print(“\(name) is being deinitialized”)<br> }<br> }</blockquote><blockquote><strong>var</strong> reference1: Student?<br> <strong>var</strong> reference2: Student?</blockquote><p>The <strong>Student</strong> class has an initializer and deinitializer and both prints a message when the instance of the class is being called. The two variables below define optional <strong>Student </strong>type.</p><blockquote>reference1 = Student(name: &quot;Rohan &quot;)</blockquote><p>so when you run the code, the output will be “<strong>Rohan is being initialized</strong>”</p><p>So now, we will assign the same <strong>Student </strong>instance reference2 to reference1</p><blockquote>reference2 = reference1</blockquote><p>and what if we set reference 1 to nil? Do you think that is going to print out “John Applessed is being deinitialized”? the answer is NO .</p><blockquote>reference2 = <strong>nil</strong></blockquote><p>after assigning reference2 to nil, it will finally print out “<strong>Rohan Appleseed is being deinitialized</strong>”. In other words, the reference count became zero.</p><p>These are simple examples of the <strong>strong reference</strong>. a strong reference is a <strong>default reference</strong></p><blockquote>reference1 = Student(name: &quot;Rohan&quot;)</blockquote><blockquote>reference2 = Student(name: &quot;Raj&quot;)</blockquote><blockquote><strong>do</strong> {</blockquote><blockquote>reference1?.name = reference2!.name</blockquote><blockquote>reference2?.name = reference1!.name</blockquote><blockquote>}</blockquote><p>The output of the code would be,</p><pre><strong>O/P:-<br></strong>Rohan is being initialized <br>Raj is being initialized</pre><p>which means that deinit never called for both objects and they just leaked.</p><h4><strong>2. Weak reference example</strong></h4><p>swift provides two ways to resolve strong reference cycles by using weak or unowned keywords</p><ul><li><strong>weak:</strong> is a reference that does not keep a strong hold on the instance it refers to, and so does not stop ARC from disposing of the referenced instance. That’s why the property must be optional.</li><li><strong>unowned:</strong> Like a weak reference, an unowned reference doesn’t keep a strong hold on the instance as well however, it is used when the other instance has the same lifetime or a longer lifetime which means expected to have a value and cannot become nil.</li></ul><blockquote>weak var reference1: Student?</blockquote><blockquote>var reference2: Student?</blockquote><blockquote>reference1 = Student(name: “Rohan”)</blockquote><blockquote>reference2 = Student(name: “Raj”)</blockquote><p>Then deinit will be called and you’ll see a message in console like below and reference1 will be immediately deallocated because variable ‘reference1’ is ‘weak’.</p><pre><strong>O/P:-</strong></pre><pre> Rohan is being initialized</pre><pre>Rohan is being deinitialized</pre><pre>Raj is being initialized</pre><p><em>************* Thanks for reading…….. </em><a href="https://randhirkushwaha3130.github.io/"><em>Randhir Raj</em></a><em> *************</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0033fe03988" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dependency Injection in Swift]]></title>
            <link>https://medium.com/@randhirraj3130/dependency-injection-in-swift-d0cc225e4ad3?source=rss-108e3839b9da------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0cc225e4ad3</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Randhir Raj]]></dc:creator>
            <pubDate>Sun, 19 Jun 2022 21:29:36 GMT</pubDate>
            <atom:updated>2022-07-07T11:24:53.452Z</atom:updated>
            <content:encoded><![CDATA[<p>Dependency Injection is often used with the intention of writing code that is loosely coupled, and thus, easier to test.</p><p>Dependency Injection is often used with the intention of writing code that is loosely coupled, and thus, easier to test.</p><p>There are three types of dependency injection —<strong> constructor injection, method injection, and property injection</strong>.</p><h3>1. P<strong>roperty Injection</strong></h3><ul><li>You should use property injection in case the dependency is truly optional</li><li>Property Injection however causes and when writing Line of Business applications, your dependencies should never be optional.</li><li>property injection is considered bad in 98% of all scenarios because it hides dependencies and there is no guarantee that the object will be injected when the class is created.</li><li>The built-in IoC container does not support property injection. You will have to use a third-party IoC container.</li></ul><p><strong>Example:-</strong></p><blockquote>class LibraryViewModel {</blockquote><blockquote>var library = Library?</blockquote><blockquote>}</blockquote><blockquote>let libraryViewModel = LibraryViewModel()</blockquote><blockquote>let library = Library()</blockquote><blockquote>libraryViewModel.library = library</blockquote><p>Here have the same view model object, but now it is no longer responsible for creating its own dependency. In this particular example, the dependency is injected into the LibraryViewModel via the library property and it receiving it from the outside. This kind of dependency injection is called <strong>property injection</strong>.</p><h3>2. C<strong>onstructor Injection</strong></h3><ul><li>Constructor injection is the process of using the constructor to pass in the dependencies of a class.</li><li>You should use constructor injection when your class has a dependency that the class requires in order to work properly.</li><li>If your class cannot work without a dependency, then inject it via the constructor.</li><li>you should use constructor injection when the dependency in question has a lifetime longer than a single method. Dependencies passed into the constructor should be useful to the class in a general way, with its use spanning multiple methods in the class. If a dependency is used in only one spot, method injection</li></ul><p><strong>Example:-</strong></p><blockquote>class LibraryViewModel {</blockquote><blockquote>var library: Library</blockquote><blockquote>init(library: Library) {</blockquote><blockquote>self.library = library</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><p>Another way to implement dependency injection is through its constructor, or initializer. A <strong>constructor injection</strong> is another type of dependency injection where the dependency is injected into an object right at its inception — the initializer.</p><h3>3. M<strong>ethod Injection</strong></h3><p>Next we have <strong>method injection</strong>, and if you’re guessing that this is where we inject dependencies through our methods.</p><p><strong>Example:-</strong></p><blockquote>protocol LibraryManager {</blockquote><blockquote>func deleteAllBooks(in library: Library){<br> }</blockquote><blockquote>}</blockquote><p>As you can see, our LibraryManager protocol has a method on it that takes in an injected dependency.</p><p><em>************* Thanks for reading…….. </em><a href="https://randhirkushwaha3130.github.io/"><em>Randhir Raj</em></a><em> *************</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0cc225e4ad3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>