<?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 Kavita Chauhan on Medium]]></title>
        <description><![CDATA[Stories by Kavita Chauhan on Medium]]></description>
        <link>https://medium.com/@kavita4310ios?source=rss-be027ca4ec13------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*oqIskMqxzv_cBdtROznk_A.jpeg</url>
            <title>Stories by Kavita Chauhan on Medium</title>
            <link>https://medium.com/@kavita4310ios?source=rss-be027ca4ec13------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 15:20:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kavita4310ios/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[Top iOS Interview Questions for Beginners]]></title>
            <link>https://medium.com/@kavita4310ios/top-ios-interview-questions-for-beginners-1a4278465826?source=rss-be027ca4ec13------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a4278465826</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Kavita Chauhan]]></dc:creator>
            <pubDate>Sun, 01 Mar 2026 10:15:22 GMT</pubDate>
            <atom:updated>2026-03-01T10:15:22.072Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this article, we’ll explore the most commonly asked Swift and iOS interview questions for beginner developers. This guide is designed to help you strengthen your fundamentals and prepare confidently for iOS developer interviews.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XqwritBYGHyN2QvMtVS7Aw.png" /></figure><h3>Swift Fundamentals</h3><ol><li>What is Swift and why was it introduced by Apple?</li><li>Difference between <strong>var and let</strong>.</li><li>Difference between <strong>struct and class</strong>.</li><li>What are 5 similarities and differences between class and structure?</li><li>What are <strong>value types vs reference types</strong>?</li><li>What are <strong>optionals</strong> in Swift?</li><li>Difference between <strong>optional binding and optional chaining</strong>.</li><li>What is <strong>nil-coalescing operator</strong>?</li><li>What are <strong>closures</strong>?</li><li>Difference between <strong>escaping and non-escaping closures</strong>.</li><li>What is <strong>type inference</strong>?</li><li>What are <strong>tuples</strong>?</li><li>What are <strong>opaque types</strong>?</li><li>What is <strong>typealias</strong>?</li><li>What are <strong>computed properties</strong>?</li><li>What are <strong>stored properties</strong>?</li><li>Difference between <strong>static vs class methods</strong>.</li><li>What are <strong>protocols</strong>?</li><li>What are <strong>protocol extensions</strong>?</li><li>What are <strong>generics</strong>?</li><li>What are <strong>associated types</strong>?</li><li>What is <strong>Codable protocol</strong>?</li><li>What is <strong>Hashable protocol</strong>?</li><li>Difference between <strong>Equatable vs Comparable</strong>.</li><li>What are <strong>access control levels in Swift</strong>?</li><li>What is <strong>defer keyword</strong>?</li><li>Difference between <strong>Any vs AnyObject</strong>.</li><li>What is <strong>KVC (Key Value Coding)</strong>?</li><li>What is <strong>KVO (Key Value Observing)</strong>?</li><li>Difference between <strong>KVC and KVO</strong>.</li><li>What are <strong>getters and setters</strong> in Swift?</li><li>What are <strong>property observers (willSet / didSet)</strong>?</li><li>Difference between <strong>computed property vs property observer</strong>.</li><li>Can <strong>extensions contain stored properties</strong>?</li><li>What can <strong>extensions add to existing types</strong>?</li><li>What are <strong>mutating functions in struct</strong>?</li><li>What is the difference between self and Self in Swift?</li><li>What is <strong>dynamic dispatch vs static dispatch</strong>?</li><li>What is <strong>method swizzling</strong>?</li><li>What is <strong>@objc in Swift</strong>?</li><li>What is <strong>@dynamicMemberLookup</strong>?</li><li>What is <strong>Result type in Swift</strong>?</li><li>Difference between <strong>guard vs if let</strong>.</li><li>What are Higher order functions. Diffrence between <strong>map, compactMap, flatMap</strong>?</li><li>What is <strong>lazy sequence</strong>?</li><li>What is <strong>inout parameter</strong>?</li><li>What is <strong>throws / try / catch</strong>?</li><li>What is <strong>rethrows</strong>?</li><li>What is <strong>@escaping</strong>?</li><li>What is iOS Architecture?</li></ol><h3>Memory Management</h3><ol><li>What is <strong>ARC (Automatic Reference Counting)</strong>?</li><li>What is <strong>strong, weak </strong>and<strong> unowned reference</strong>?</li><li>What is a <strong>retain cycle</strong>?</li><li>How do you avoid retain cycles?</li><li>How closures can cause <strong>memory leaks</strong>?</li><li>What is <strong>heap vs stack memory</strong>?</li><li>What is <strong>copy-on-write</strong>?</li><li>What happens when <strong>two objects strongly reference each other</strong>?</li><li>How do you detect memory leaks?</li><li>What is <strong>memory graph debugger</strong>?</li><li>What is <strong>autoreleasepool</strong>?</li><li>What is <strong>lazy property</strong>?</li><li>What is <strong>deinitialization (deinit)</strong>?</li><li>Difference between <strong>weak vs unowned</strong>.</li><li>When should you use <strong>weak vs unowned</strong>?</li><li>What happens when <strong>unowned reference becomes nil</strong>?</li><li>What is <strong>capture list in closures</strong>?</li><li>What is <strong>[weak self] vs [unowned self]</strong>?</li><li>What is <strong>retain count</strong>?</li><li>How ARC works internally?</li><li>What is <strong>strong reference cycle between closures and classes</strong>?</li><li>What happens when <strong>weak reference becomes nil</strong>?</li><li>How does <strong>ARC handle structs</strong>?</li></ol><h3>UIKit &amp; App Lifecycle</h3><ol><li>What is <strong>UIKit</strong>?</li><li>What is <strong>AppDelegate</strong>?</li><li>What is <strong>SceneDelegate</strong>?</li><li>Explain <strong>app lifecycle </strong>and<strong> app State</strong>.</li><li>Explain <strong>ViewController lifecycle</strong>.</li><li>Difference between <strong>viewDidLoad and viewDidAppear</strong>.</li><li>Difference between <strong>viewWillLayoutSubviews</strong> and <strong>viewDidLayoutSubviews?</strong></li><li>Difference between <strong>frame vs bounds</strong>.</li><li>What is <strong>AutoLayout</strong>?</li><li>What are <strong>constraints</strong>?</li><li>What is <strong>intrinsic content size</strong>?</li><li>What is <strong>content hugging priority</strong>?</li><li>What is <strong>compression resistance priority</strong>?</li><li>What is <strong>UITableView</strong>?</li><li>Difference between <strong>UITableViewDelegate vs UITableViewDataSource</strong>.</li><li>What is <strong>ReuseIdentifier</strong>?</li><li>What is <strong>dequeueReusableCell</strong>?</li><li>What is <strong>UICollectionView</strong>?</li><li>What is <strong>Responder Chain</strong>?</li><li>What is <strong>target-action pattern</strong>?</li><li>What is <strong>UIView hierarchy</strong>?</li><li>What is <strong>layoutSubviews()</strong>?</li><li>What is <strong>draw() method</strong>?</li><li>Difference between <strong>setNeedsLayout vs layoutIfNeeded</strong>.</li><li>What is <strong>navigation controller</strong>?</li><li>Difference between <strong>viewWillAppear, viewDidAppear and viewDidDisappear</strong>.</li><li>What is <strong>safe area</strong>?</li><li>What is <strong>layoutMargins</strong>?</li></ol><h3>OOP Concepts in Swift</h3><ol><li>What is OOPs concepts?</li><li>What is <strong>Object-Oriented Programming (OOP)</strong>?</li><li>What are the <strong>four pillars of OOP</strong>?</li><li>What is<strong> Encapsulation,</strong> <strong>Inheritance, Polymorphism </strong>and<strong> Abstraction</strong>?</li><li>Difference between <strong>overloading vs overriding</strong>.</li><li>What is <strong>dynamic dispatch </strong>and<strong> static dispatch</strong>?</li><li>How does <strong>Swift implement polymorphism</strong>?</li></ol><h3>Protocols</h3><ol><li>What is a protocol in Swift, and why are protocols important even though Swift supports OOP?</li><li>Can we create <strong>optional protocol methods in Swift</strong>?</li><li>What is <strong>@objc optional protocol method</strong>?</li><li>Difference between <strong>protocol vs abstract class</strong>.</li><li>What is <strong>default implementation in protocol extension</strong>?</li><li>What is <strong>Self requirement in protocols</strong>?</li></ol><h3>Networking</h3><ol><li>What is <strong>REST API</strong>?</li><li>What is <strong>URLSession</strong>?</li><li>Difference between <strong>dataTask vs downloadTask</strong>.</li><li>What is <strong>JSON</strong>?</li><li>What is <strong>Codable</strong>?</li><li>Difference between <strong>JSONSerialization vs Codable</strong>.</li><li>How to handle <strong>API errors</strong>?</li><li>What is <strong>HTTP status code</strong>?</li><li>What is <strong>GET vs POST</strong>?</li><li>What is <strong>PUT vs PATCH</strong>?</li><li>What is <strong>API pagination</strong>?</li><li>What is <strong>request timeout</strong>?</li><li>What is <strong>retry mechanism</strong>?</li><li>What is <strong>API caching</strong>?</li><li>What is <strong>Alamofire</strong>?</li><li>Difference between <strong>URLSession vs Alamofire</strong>.</li><li>What is <strong>interceptor in networking</strong>?</li><li>What is <strong>authentication token</strong>?</li><li>What is <strong>refresh token</strong>?</li><li>What is <strong>WebSocket</strong>?</li><li>What are the different ways to upload images to a server in iOS?</li><li>What is <strong>URLRequest </strong>and<strong> HTTP headers</strong>?</li><li>What is <strong>multipart/form-data</strong>?</li></ol><h3>Data Persistence</h3><ol><li>What is <strong>UserDefaults</strong>?</li><li>When should you use <strong>UserDefaults</strong>?</li><li>What is <strong>Keychain</strong>?</li><li>What is <strong>Core Data</strong>?</li><li>What is <strong>NSManagedObject</strong>?</li><li>What is <strong>Core Data stack</strong>?</li><li>What is <strong>Core Data relationship</strong>?</li><li>What is <strong>fetch request</strong>?</li><li>What is <strong>Core Data migration</strong>?</li><li>Difference between <strong>SQLite vs Core Data</strong>.</li><li>What is <strong>Realm database</strong>?</li><li>How to store <strong>images in database</strong>?</li><li>What is <strong>file manager</strong>?</li><li>What is <strong>sandbox in iOS</strong>?</li><li>What is <strong>persistent storage</strong>?</li><li>What are the rules for deleting data in <strong>Core Data</strong>?</li></ol><h3>Architecture &amp; Design Patterns</h3><ol><li>What is <strong>MVC pattern</strong>?</li><li>How many <strong>Architectures</strong> use in iOS?</li><li>What are problems with <strong>MVC</strong>?</li><li>What is <strong>MVVM</strong>?</li><li>What is <strong>Coordinator pattern</strong>?</li><li>What is <strong>Clean Architecture</strong>?</li><li>What is <strong>Dependency Injection</strong>?</li><li>What is <strong>protocol-oriented programming</strong>?</li><li>What is <strong>singleton pattern</strong>?</li><li>What is <strong>observer pattern</strong>?</li><li>What is <strong>delegate pattern</strong>?</li><li>What is <strong>factory pattern</strong>?</li><li>What is <strong>repository pattern</strong>?</li><li>What is <strong>tight coupling vs loose coupling</strong>?</li><li>What is <strong>SOLID principle</strong>?</li><li>What is <strong>Single Responsibility Principle</strong>?</li><li>What is <strong>Open Closed Principle</strong>?</li><li>What is <strong>Liskov Substitution Principle</strong>?</li><li>What is <strong>Interface Segregation Principle</strong>?</li><li>What is <strong>Dependency Inversion Principle</strong>?</li><li>What is <strong>modular architecture</strong>?</li><li>What is <strong>code reusability</strong>?</li><li>What is <strong>service layer architecture</strong>?</li><li>What is <strong>repository layer</strong>?</li><li>What is <strong>VIPER architecture</strong>?</li><li>Difference between <strong>MVC vs MVVM vs VIPER</strong>.</li></ol><h3>Concurrency</h3><ol><li>What is <strong>multithreading</strong>?</li><li>What is <strong>main thread</strong>?</li><li>What is <strong>background thread</strong>?</li><li>What is <strong>GCD (Grand Central Dispatch)</strong>?</li><li>What is <strong>DispatchQueue</strong>?</li><li>Difference between <strong>serial vs concurrent queue</strong>.</li><li>What is <strong>async vs sync</strong>?</li><li>What is <strong>deadlock</strong>?</li><li>What is <strong>race condition</strong>?</li><li>What is <strong>data race</strong>?</li><li>What is <strong>DispatchGroup</strong>?</li><li>What is <strong>OperationQueue</strong>?</li><li>What is <strong>Task in Swift concurrency</strong>?</li><li>What is <strong>async/await</strong>?</li><li>What is <strong>actor</strong>?</li><li>What is <strong>Task cancellation</strong>?</li><li>What is <strong>MainActor</strong>?</li><li>What is <strong>thread safety</strong>?</li><li>What is <strong>Thread Sanitizer</strong>?</li><li>What is <strong>structured concurrency</strong>?</li><li>Which thread runs with the highest priority in an iOS application?</li><li>Why we update UI in <strong>main thread</strong>?</li><li>What is <strong>TaskGroup</strong>?</li><li>What is <strong>Detached Task</strong>?</li><li>What is <strong>Sendable protocol</strong>?</li><li>What is <strong>nonisolated keyword</strong>?</li><li>What is <strong>isolated parameter</strong>?</li><li>What is <strong>global actor</strong>?</li><li>Difference between <strong>Task vs DispatchQueue</strong>.</li></ol><h3>Testing &amp; Debugging</h3><ol><li>What is <strong>Unit Testing</strong>?</li><li>What is <strong>UI Testing</strong>?</li><li>What is <strong>XCTest</strong>?</li><li>What is <strong>mocking</strong>?</li><li>What is <strong>dependency injection in testing</strong>?</li><li>What is <strong>breakpoint</strong>?</li><li>What is <strong>symbolicated crash log</strong>?</li><li>What is <strong>debugger</strong>?</li><li>What is <strong>LLDB</strong>?</li><li>What is <strong>memory leak debugging</strong>?</li><li>What is <strong>Instruments tool</strong>?</li><li>What is <strong>Time Profiler</strong>?</li><li>What is <strong>Leaks instrument</strong>?</li><li>What is <strong>crash reporting tool</strong>?</li></ol><h3>Security &amp; Deployment</h3><ol><li>What is <strong>Bundle ID, App ID </strong>and<strong> Team ID</strong>?</li><li>What is <strong>code signing</strong>?</li><li>What is <strong>provisioning profile</strong>?</li><li>What is <strong>certificate in iOS</strong>?</li><li>Difference between <strong>development vs distribution certificate</strong>.</li><li>What is <strong>TestFlight</strong>?</li><li>What is <strong>App Store review process</strong>?</li><li>What is <strong>App Transport Security (ATS)</strong>?</li><li>What is <strong>SSL pinning</strong>?</li><li>What is <strong>encryption vs hashing</strong>?</li><li>What is <strong>app thinning</strong>?</li><li>What is <strong>Bitcode</strong>?</li><li>What is <strong>jailbreaking</strong>?</li><li>What is <strong>app sandbox</strong>?</li><li>What is <strong>push notification certificate</strong>?</li><li>What is <strong>APNS</strong>?</li><li>What is <strong>Firebase Cloud Messaging (FCM)</strong>?</li><li>What is <strong>background modes in iOS</strong>?</li></ol><h3>UIKit Navigation</h3><ol><li>What is <strong>UINavigationController</strong>?</li><li>What is the difference between <strong>push and present</strong>?</li><li>What is <strong>modal presentation</strong>?</li><li>What are <strong>different modal presentation styles</strong>?</li><li>Difference between <strong>pushViewController and presentViewController</strong>.</li><li>How do you <strong>pop a view controller</strong>?</li><li>What is <strong>popToRootViewController</strong>?</li><li>What is <strong>popToViewController</strong>?</li><li>What is the <strong>navigation stack</strong>?</li><li>How can you <strong>pass data between view controllers</strong>?</li><li>How to pass data <strong>back to previous controller</strong>?</li><li>What are the <strong>ways to pass data between view controllers</strong>?</li><li>What is <strong>delegate pattern used in navigation</strong>?</li><li>What is <strong>closure based navigation communication</strong>?</li><li>What is <strong>NotificationCenter used for navigation communication</strong>?</li><li>What is the <strong>Coordinator Pattern</strong>?</li><li>Why is navigation often <strong>moved out of ViewController in MVVM</strong>?</li><li>How do you <strong>manage navigation in modular architecture</strong>?</li><li>How do you <strong>handle deep links</strong>?</li><li>What is <strong>universal linking</strong>?</li><li>How do you <strong>handle push notification navigation</strong>?</li><li>How do you <strong>restore navigation state after app relaunch</strong>?</li><li>How to <strong>avoid navigation memory leaks</strong>?</li><li>How to <strong>handle multi-flow navigation (login → main → profile)</strong>?</li><li>How to <strong>test navigation logic</strong>?</li></ol><h3>Storyboard Navigation</h3><ol><li>What is <strong>segue</strong>?</li><li>What are <strong>different types of segues</strong>?</li><li>What is <strong>prepare(for segue:) method</strong>?</li><li>How do you <strong>programmatically trigger segue</strong>?</li><li>What is <strong>unwind segue</strong>?</li></ol><h3>SwiftUI Navigation</h3><ol><li>What is <strong>NavigationStack</strong>?</li><li>What is <strong>NavigationView (deprecated)</strong>?</li><li>What is <strong>NavigationLink</strong>?</li><li>How does <strong>programmatic navigation work in SwiftUI</strong>?</li><li>What is <strong>NavigationPath</strong>?</li><li>How do you <strong>pop to root in SwiftUI navigation</strong>?</li><li>How do you <strong>handle deep navigation stacks</strong>?</li><li>How do you <strong>pass data during navigation in SwiftUI</strong>?</li></ol><h3>Code Coverage (Testing)</h3><ol><li>What is <strong>code coverage and how do you check it in Xcode</strong>?</li><li>Why is <strong>code coverage important in unit testing</strong>?</li><li>How do you <strong>measure code coverage in Xcode</strong>?</li><li>What is <strong>line coverage vs branch coverage</strong>?</li><li>What is a <strong>good code coverage percentage for production apps</strong>?</li><li>How can you <strong>increase code coverage in a project</strong>?</li><li>Does <strong>100% code coverage guarantee bug-free code</strong>?</li><li>How do you <strong>enable code coverage in XCTest</strong>?</li><li>How does <strong>code coverage help maintain code quality</strong>?</li><li>What are the <strong>limitations of code coverage metrics</strong>?</li></ol><h3>Profiling &amp; Performance</h3><ol><li>What is <strong>profiling</strong> in iOS development?</li><li>Why do we use <strong>profiling tools</strong>?</li><li>What is <strong>Instruments in Xcode</strong>?</li><li>What is <strong>Time Profiler</strong>?</li><li>What is <strong>Leaks instrument</strong>?</li><li>What is <strong>Allocations instrument</strong>?</li><li>What is <strong>Energy Log</strong>?</li><li>What is <strong>Core Animation instrument</strong>?</li><li>How do you <strong>detect memory leaks using Instruments</strong>?</li><li>How do you <strong>find CPU-heavy functions using Time Profiler</strong>?</li><li>What causes <strong>slow app launch time</strong>?</li><li>What is <strong>Cold Launch vs Warm Launch</strong>?</li><li>What is <strong>lazy loading </strong>and how does it improve<strong> performance</strong>?</li><li>How do you <strong>optimize table view performance</strong>?</li><li>How do you <strong>avoid image rendering issues</strong>?</li></ol><h3>Performance Debugging</h3><ol><li>How do you <strong>analyze slow app launch time</strong>?</li><li>How do you <strong>identify main thread blocking</strong>?</li><li>How do you <strong>debug scrolling performance issues</strong>?</li><li>What causes <strong>UI stuttering</strong>?</li><li>How do you <strong>optimize large image loading</strong>?</li><li>How do you <strong>measure memory footprint of an app</strong>?</li><li>What is image caching in iOS?</li><li>What is <strong>background thread processing</strong>?</li><li>What tools help <strong>analyze performance in production</strong>?</li><li>How do you <strong>debug memory leaks</strong>?</li><li>What tools do you use to <strong>analyze app performance</strong>?</li><li>What is the <strong>difference between debugging and profiling</strong>?</li></ol><h3>SwiftUI Fundamentals</h3><ol><li>What is <strong>SwiftUI</strong>?</li><li>Difference between <strong>SwiftUI vs UIKit</strong>.</li><li>What is <strong>@State</strong>?</li><li>What is <strong>@Binding</strong>?</li><li>What is <strong>@ObservedObject</strong>?</li><li>What is <strong>@StateObject</strong>?</li><li>What is <strong>@EnvironmentObject</strong>?</li><li>What is <strong>ViewBuilder</strong>?</li><li>What is <strong>NavigationStack</strong>?</li><li>How do you create <strong>simple and grid lists in SwiftUI</strong>?</li><li>Difference between <strong>VStack, HStack, ZStack</strong>.</li><li>What is <strong>GeometryReader</strong>?</li><li>What is <strong>LazyVStack</strong>?</li><li>What is <strong>View modifier</strong>?</li><li>What is <strong>Identifiable protocol</strong>?</li><li>How does <strong>state update re-render UI</strong>?</li><li>What is <strong>PreferenceKey</strong>?</li><li>How to perform <strong>navigation in SwiftUI</strong>?</li><li>What is <strong>Combine used in SwiftUI</strong>?</li><li>What is <strong>ObservableObject</strong>?</li><li>What is <strong>@MainActor in SwiftUI</strong>?</li><li>What is <strong>@Environment</strong>?</li><li>What is <strong>.task modifier</strong>?</li><li>What is <strong>View identity</strong>?</li><li>What is <strong>diffing algorithm in SwiftUI</strong>?</li><li>What is <strong>EquatableView</strong>?</li></ol><h3>Common Questions</h3><ol><li>Can extension override methods?</li><li>Can struct inherit from another struct?</li><li>Why do Swift structs not support inheritance?</li><li>What happens if two protocols have the same method name?</li><li>What is the final keyword in Swift?</li><li>What is a required initializer?</li><li>What is a convenience initializer?</li><li>What is a failable initializer?</li><li>Why does SwiftUI sometimes redraw the entire view?</li><li>Why are structs preferred over classes in SwiftUI?</li><li>What happens inside ARC when the retain count becomes zero?</li><li>Why must weak references be optional?</li><li>Why must UI updates happen on the main thread internally?</li><li>What is the difference between private and fileprivate?</li><li>What is the difference between public and open?</li><li>What is the default access level in Swift?</li><li>Can a public class contain private methods?</li><li>Can a subclass override a public method?</li><li>Can a subclass override an open method?</li><li>Why did Swift introduce fileprivate in Swift 3?</li><li>What is the access level of extensions in Swift?</li><li>Can we extend a private type outside the file?</li><li>What happens if a method has a lower access level than its class?</li><li>What is the access level of protocol requirements?</li><li>Why is open more permissive than public?</li><li>Can an open class contain private properties?</li><li>Can we subclass an open class outside the module?</li><li>Can we override public methods outside the module?</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a4278465826" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SwiftUI Interview Questions]]></title>
            <link>https://medium.com/@kavita4310ios/swiftui-interview-questions-cb6c79044b4f?source=rss-be027ca4ec13------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb6c79044b4f</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Kavita Chauhan]]></dc:creator>
            <pubDate>Thu, 26 Feb 2026 18:44:22 GMT</pubDate>
            <atom:updated>2026-02-26T18:44:22.270Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>In this article, we’ll cover the most frequently asked SwiftUI interview questions to help you prepare effectively.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xBmghVOtMhM0mmU-H_jMnA.png" /></figure><h3>SwiftUI Fundamentals</h3><ol><li>Explain SwiftUI lifecycle vs UIKit lifecycle.</li><li>Explain the SwiftUI App protocol lifecycle.</li><li>How does SwiftUI rendering system work internally?</li><li>What is view identity in SwiftUI?</li><li>What determines view identity?</li><li>What is the difference between @State, @Binding, @ObservedObject, @StateObject, @EnvironmentObject?</li><li>When should you use @StateObject instead of @ObservedObject?</li><li>What happens if you misuse @ObservedObject?</li><li>How does @Binding work internally?</li><li>What is @Environment?</li><li>How does @EnvironmentObject propagate?</li><li>When should you avoid @EnvironmentObject?</li><li>Difference between some View and AnyView.</li><li>What are opaque return types?</li><li>Why are SwiftUI views structs?</li><li>Why is UI not recreated fully if views are structs?</li><li>What happens internally when @State changes?</li><li>When does SwiftUI recreate a view vs update it?</li><li>Difference between .id() and Identifiable.</li></ol><h3>SwiftUI Architecture</h3><ol><li>How would you structure a large-scale SwiftUI application?</li><li>Explain MVVM in SwiftUI and its data flow.</li><li>How do you implement Dependency Injection in SwiftUI?</li><li>What is a Dependency Container pattern?</li><li>How do you modularize a SwiftUI project?</li><li>How would you structure a 100+ screen app?</li><li>How do you handle navigation in large SwiftUI apps?</li><li>How do you implement Coordinator pattern in SwiftUI?</li><li>How do you integrate Clean Architecture with SwiftUI?</li><li>How do you manage global state safely?</li><li>How do you prevent state duplication across modules?</li><li>How would you design scalable feature-based modules?</li><li>How do you handle localization in SwiftUI?</li><li>How do you handle dark mode properly?</li></ol><h3>State Management &amp; Data Flow</h3><ol><li>Explain SwiftUI data flow.</li><li>What causes a SwiftUI view to re-render?</li><li>How does SwiftUI diff the view hierarchy internally?</li><li>What is the role of Identity and Hashable?</li><li>Why does ForEach require Identifiable?</li><li>What is EquatableView?</li><li>How do you prevent unnecessary re-renders?</li><li>What is SceneStorage vs AppStorage?</li><li>How does state restoration work?</li><li>What is view invalidation?</li><li>What is a Transaction in SwiftUI?</li><li>How does animation tie into state updates?</li><li>How do PreferenceKey and AnchorPreference work?</li><li>How do custom EnvironmentValues work?</li></ol><h3>Concurrency in SwiftUI</h3><ol><li>How do you use Task {} in SwiftUI</li><li>Difference between .task, .onAppear, .onReceive.</li><li>How does structured concurrency work?</li><li>How do you cancel a Task?</li><li>What is TaskGroup?</li><li>What is actor and why is it needed?</li><li>What does isolated mean?</li><li>When should you mark a method nonisolated?</li><li>Why can’t nonisolated methods access actor state?</li><li>What is @MainActor?</li><li>Difference between @MainActor and DispatchQueue.main.</li><li>What happens if you update UI from background thread?</li><li>What is Sendable?</li><li>What is @unchecked Sendable?</li><li>What is strict concurrency checking?</li><li>What is @preconcurrency?</li><li>How does structured concurrency prevent memory leaks?</li></ol><h3>Navigation</h3><ol><li>Difference between NavigationView and NavigationStack.</li><li>How does NavigationPath work internally?</li><li>Programmatic navigation in SwiftUI.</li><li>How to pass data between views?</li><li>How to manage deep linking?</li><li>How to manage navigation in modular architecture?</li><li>How does state-driven navigation work?</li></ol><h3>Layout System</h3><ol><li>How does SwiftUI layout system work?</li><li>What is layout priority?</li><li>What is GeometryReader?</li><li>Why can misuse of GeometryReader cause performance issues?</li><li>Difference between VStack, HStack, ZStack, LazyVStack.</li><li>How does LazyVStack differ internally from VStack?</li><li>Frame vs fixedSize.</li><li>What is the Layout protocol (iOS 16+)?</li><li>How do custom Layouts work?</li><li>What is alignment guide?</li><li>How does redaction (skeleton loading) work?</li></ol><h3>Performance Optimization</h3><ol><li>How to reduce view body recalculations?</li><li>When should you use @ViewBuilder?</li><li>Why is AnyView bad for performance?</li><li>How to optimize a list with 50,000 rows?</li><li>Lazy stacks vs regular stacks performance difference.</li><li>How would you debug SwiftUI performance issues?</li><li>How do you detect memory leaks?</li><li>How do you use Instruments with SwiftUI?</li><li>How to reduce launch time?</li><li>How to reduce app size?</li><li>How does SwiftUI avoid unnecessary re-renders?</li></ol><h3>SwiftUI + UIKit Integration</h3><ol><li>What is UIViewRepresentable?</li><li>What is UIViewControllerRepresentable?</li><li>How to embed SwiftUI inside UIKit?</li><li>How to migrate UIKit project gradually?</li><li>What is Coordinator in Representable?</li><li>How does data flow between UIKit and SwiftUI?</li></ol><h3>Combine + SwiftUI</h3><ol><li>Difference between Combine and async/await.</li><li>How does @Published work internally?</li><li>How to debounce search API?</li><li>How to use onReceive?</li><li>How to create a custom Publisher?</li><li>Memory management in Combine.</li><li>How does Combine cancellation work?</li></ol><h3>Data Persistence</h3><ol><li>What is SwiftData?</li><li>SwiftData vs Core Data.</li><li>How does @Query work?</li><li>How to integrate persistence with MVVM?</li><li>Offline-first architecture design?</li><li>How to handle pagination for large datasets?</li></ol><h3>Testing SwiftUI</h3><ol><li>How do you unit test ViewModel?</li><li>Snapshot testing in SwiftUI.</li><li>UI testing SwiftUI views.</li><li>Testing async SwiftUI code.</li><li>How to mock network layer?</li><li>How to test navigation?</li></ol><h3>@ViewBuilder &amp; Result Builder</h3><ol><li>What is @ViewBuilder?</li><li>How does it allow multiple views without return?</li><li>How does @ViewBuilder work internally?</li><li>Difference between @ViewBuilder and @resultBuilder.</li><li>Can we create custom result builder?</li><li>How does conditional rendering work inside ViewBuilder?</li><li>Can you build your own DSL using result builder?</li></ol><h3>Swift Internals &amp; ABI</h3><ol><li>What is @frozen?</li><li>Why are some enums marked @frozen?</li><li>What is ABI stability?</li><li>Why was Swift 5 important for ABI stability?</li><li>What is module stability?</li><li>What is @inlinable?</li><li>What is @usableFromInline?</li><li>Why doesn’t Swift support multiple inheritance?</li><li>What is the diamond problem?</li></ol><p><strong>Conclusion</strong><br><em>SwiftUI is more than just building screens — it’s about understanding how state, data flow, and rendering work together behind the scenes.<br>Focus on strong fundamentals and keep practicing with real projects.<br>Keep learning, keep building, and stay consistent — becoming confident in SwiftUI is absolutely achievable.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb6c79044b4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview Questions in Swift Part - 5]]></title>
            <link>https://medium.com/@kavita4310ios/interview-questions-in-swift-part-5-07578e44cd94?source=rss-be027ca4ec13------2</link>
            <guid isPermaLink="false">https://medium.com/p/07578e44cd94</guid>
            <category><![CDATA[questions-answers]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Kavita Chauhan]]></dc:creator>
            <pubDate>Sun, 05 Jan 2025 17:23:19 GMT</pubDate>
            <atom:updated>2025-01-06T17:10:16.466Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this part, we will cover some other iOS Interview questions that are commonly asked by interviewers during job interviews. Let’s get started.</em></p><ol><li><strong><em>What are Access control in Swift and their types?</em></strong></li></ol><p><em>Ans - In Swift, </em><strong><em>access control</em></strong><em> determines the visibility and accessibility of code entities (such as classes, structs, properties, methods, etc.) across different modules and within the same module. Access specifiers allow you to manage the scope of where these entities can be accessed from. Swift provides five levels of access control:</em></p><h4><em>1. </em><em>open</em></h4><ul><li><strong><em>Visibility</em></strong><em>: Accessible from any module, and can also be subclassed or overridden in another module.</em></li><li><strong><em>Use Case</em></strong><em>: Primarily used for classes and class members that need to be exposed to other modules and can be subclassed or overridden outside of the module where they are defined.</em></li><li><strong><em>Applicable to</em></strong><em>: Classes, methods, and properties.</em></li></ul><pre>open class MyClass {<br>    open var name: String = &quot;&quot;<br>    <br>    open func doSomething() {<br>        // Do something<br>    }<br>}</pre><h4>2.<em> </em><em>public</em></h4><ul><li><strong><em>Visibility</em></strong><em>: Accessible from any module, but </em><strong><em>cannot</em></strong><em> be subclassed or overridden outside the module.</em></li><li><strong><em>Use Case</em></strong><em>: Used when you want to expose functionality to other modules but don’t want it to be further subclassed or modified.</em></li><li><strong><em>Applicable to</em></strong><em>: Classes, structs, enums, methods, and properties</em></li></ul><pre>public class MyClass {<br>    public var name: String = &quot;&quot;<br>    <br>    public func doSomething() {<br>        // Do something<br>    }<br>}</pre><h4><em>3. </em><em>internal (default)</em></h4><ul><li><strong><em>Visibility</em></strong><em>: Accessible only within the same module (i.e., the app or framework).</em></li><li><strong><em>Use Case</em></strong><em>: The default access level in Swift. It is used when you want to restrict access to the code within the same module, which is common for app or framework-level logic that shouldn’t be exposed to external modules.</em></li><li><strong><em>Applicable to</em></strong><em>: All types and members (methods, properties, etc.)</em></li></ul><pre>class MyClass {<br>    var name: String = &quot;&quot;<br>    <br>    func doSomething() {<br>        // Do something<br>    }<br>}</pre><h4>4. <em>fileprivate</em></h4><ul><li><strong><em>Visibility</em></strong><em>: Accessible only within the same source file.</em></li><li><strong><em>Use Case</em></strong><em>: Used to limit the access of an entity to the file where it is defined. This is useful when you want to restrict access to other parts of your module while allowing certain code entities to interact with each other within a single file.</em></li><li><strong><em>Applicable to</em></strong><em>: Types, methods, properties, and extensions.</em></li></ul><pre>class MyClass {<br>    fileprivate var name: String = &quot;&quot;<br>    <br>    fileprivate func doSomething() {<br>        // Do something<br>    }<br>}</pre><h4>5<em>. </em><em>private</em></h4><ul><li><strong><em>Visibility</em></strong><em>: Accessible only within the same enclosing declaration (class, struct, or extension).</em></li><li><strong><em>Use Case</em></strong><em>: Most restrictive access control. Used to hide implementation details that should not be accessible outside the scope of the current class or struct.</em></li><li><strong><em>Applicable to</em></strong><em>: Methods, properties, and variables.</em></li></ul><pre>class MyClass {<br>    private var name: String = &quot;&quot;<br>    <br>    private func doSomething() {<br>        // Do something<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n4uqr543NFXKSobuTZnWxg.png" /></figure><h4><em>Access Control Features</em></h4><ul><li><strong><em>Inheritance and Overriding</em></strong><em>: The </em><em>open access level allows inheritance and overriding in external modules, whereas </em><em>public allows access but not inheritance/overriding outside the module.</em></li><li><strong><em>Default Access</em></strong><em>: If no access control is specified, it defaults to </em><em>internal within the module.</em></li></ul><p><strong><em>2. </em>UIKit </strong>vs <strong>SwiftUI</strong> <strong><em>?</em></strong></p><p><em>Ans - </em><strong><em>SwiftUI</em></strong><em> is a user interface toolkit that allows developers to design apps in a </em><strong><em>declarative</em></strong><em> manner, view and layout updates automatically when data changes, while, </em><strong><em>UIKit</em></strong><em> is an older, and follow </em><strong><em>imperative</em></strong><em> manner that requires developers to specify </em><strong><em>how</em></strong><em> the user interface should behave and update, step by step.With UIKit, we manage the view hierarchy, layout, and state manually.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ngjT0U-Z6V5ih_41Tc1dew.png" /></figure><p><strong><em>3. What is the use Info.Plist file in App?</em></strong></p><p><em>Ans - The </em><em>Info.plist file (</em><strong><em>Information Property List</em></strong><em>) is a crucial configuration file in iOS and macOS applications. It is an XML file that contains key-value pairs that define essential settings and properties about the app, such as metadata, permissions, configurations, and behaviors that the system needs in order to properly launch and interact with the app.</em></p><h4><em>Key Uses of the </em><em>Info.plist File:</em></h4><p><strong><em>App Metadata:</em></strong></p><ul><li><strong><em>Bundle Identifier</em></strong><em> (</em><em>CFBundleIdentifier): A unique identifier for your app, used to distinguish it from other apps in the App Store or on a device.</em></li><li><strong><em>App Version</em></strong><em> (</em><em>CFBundleShortVersionString): Defines the version number of the app that is visible to users (e.g., &quot;1.0&quot;).</em></li><li><strong><em>Build Version</em></strong><em> (</em><em>CFBundleVersion): A number representing the build version of the app, typically used for internal tracking of different app builds.</em></li></ul><p><strong><em>App Permissions (Privacy and Security):</em></strong></p><ul><li><strong><em>Privacy Settings</em></strong><em>: The </em><em>Info.plist contains keys related to permissions for accessing sensitive data or system features, such as the camera, microphone, location services, contacts, etc. For example:</em></li><li><em>NSCameraUsageDescription: Describes why the app needs camera access (shown in a permission prompt).</em></li><li><em>NSLocationWhenInUseUsageDescription: Explains why the app needs location access.</em></li><li><em>NSMicrophoneUsageDescription: Requests permission to use the device&#39;s microphone.</em></li></ul><p><strong><em>App Configuration:</em></strong></p><ul><li><strong><em>Launch Options</em></strong><em>: Settings that control how your app behaves during launch, such as setting the initial interface orientation (</em><em>UISupportedInterfaceOrientations), or specifying the app&#39;s required device capabilities.</em></li><li><strong><em>Main Interface</em></strong><em> (</em><em>UIMainStoryboardFile): Defines the initial storyboard to load when the app is launched (relevant for UIKit-based apps).</em></li><li><strong><em>Scene Configuration</em></strong><em> (</em><em>UIApplicationSceneManifest): For apps supporting multiple scenes (introduced in iOS 13), it defines how your app should manage multiple windows.</em></li></ul><p><strong><em>App Icons and Launch Images:</em></strong></p><ul><li><strong><em>App Icon</em></strong><em> (</em><em>CFBundleIcons): Specifies the set of app icons in different sizes for various devices and screen resolutions.</em></li><li><strong><em>Launch Image</em></strong><em> (</em><em>UILaunchImages): Defines the splash screen or launch images that appear when the app is starting.</em></li></ul><p><strong><em>App Capabilities:</em></strong></p><ul><li><strong><em>App Capabilities</em></strong><em> (</em><em>UIBackgroundModes): Enables or disables specific app features, such as background fetch, location updates, or background audio.</em></li><li><strong><em>Push Notifications</em></strong><em>: Configures the app to receive remote push notifications by including keys like </em><em>UIBackgroundModes and </em><em>UIRemoteNotificationType.</em></li></ul><p><strong><em>App Environment Configuration:</em></strong></p><ul><li><strong><em>Environment Variables</em></strong><em>: You can set custom environment variables or configurations needed for the app to operate, such as API keys or debug settings.</em></li><li><strong><em>App Transport Security (ATS)</em></strong><em>: Controls network security and specifies the rules for making HTTP/HTTPS requests, such as setting exceptions for non-secure connections to specific domains.</em></li></ul><p><strong><em>Custom URL Schemes:</em></strong></p><ul><li><strong><em>Custom URL Scheme</em></strong><em> (</em><em>CFBundleURLTypes): Registers custom URL schemes to enable your app to open or interact with other apps. For instance, opening an app via a URL like </em><em>myapp://.</em></li></ul><p><strong><em>Universal Links:</em></strong></p><ul><li><strong><em>Universal Links</em></strong><em> (</em><em>com.apple.developer.associated-domains): Enables your app to open specific URLs directly from a website (for example, clicking a link on a webpage that opens the app instead of the browser).</em></li></ul><p><strong><em>App Localization:</em></strong></p><ul><li><strong><em>Localization</em></strong><em>: The </em><em>Info.plist can also include localization keys (such as </em><em>CFBundleDisplayName) to define language-specific settings, such as app name and descriptions, for different regions or languages.</em></li></ul><p><strong><em>4. What are Type</em> <em>aliases in Swift?</em></strong></p><p><em>Ans - In Swift, </em><strong><em>type aliases</em></strong><em> are a way to give a new name to an existing type. They don’t create new types, but rather provide an alternative, more readable name for a type. Type aliases are useful when working with complex types, such as closures, It provide clarity in code.</em></p><pre>typealias CompletionHandler = (Bool, String) -&gt; Void<br><br>func fetchData(completion: CompletionHandler) {<br>    // Simulate data fetch<br>    completion(true, &quot;Data fetched successfully&quot;)<br>}<br><br>fetchData { success, message in<br>    if success {<br>        print(message)<br>    }<br>}</pre><p><strong><em>5. What is the use of inout keywords in Swift?</em></strong></p><p><em>Ans - In Swift, the </em><em>inout keyword is used to indicate that a parameter passed to a function can be modified </em><strong><em>directly</em></strong><em> inside the function. It allows the function to </em><strong><em>mutate</em></strong><em> the value of the parameter, and the changes will be reflected </em><strong><em>outside</em></strong><em> the function as well. This is particularly useful when you want to pass a value to a function and have that function modify the value without returning it.</em></p><pre>func increment(value: inout Int) {<br>    value += 1<br>}<br><br>var number = 5<br>increment(value: &amp;number)<br>print(number)  // Output: 6</pre><p><strong><em>6. What is the use of defer keywords in Swift, If we will add multiple defer statements then which order it will follow ?</em></strong></p><p><em>Ans - The </em><em>defer keyword in Swift is used to define a block of code that is </em><strong><em>executed just before the current scope is exited</em></strong><em>, no matter how the scope is exited (whether normally or via an error). It allows you to ensure that certain cleanup or finalization tasks are always performed, such as releasing resources, closing file handles, or restoring state, even if the function returns early due to an error or an explicit </em><em>return.</em></p><pre>    func testFunction(name: String)-&gt; String {<br>        <br>        print(&quot;Start&quot;)<br>        <br>        defer {<br>            print(&quot;First defer&quot;)<br>        }<br>        <br>        defer {<br>            print(&quot;Second defer&quot;)<br>        }<br>        <br>        defer {<br>            print(&quot;Third defer&quot;)<br>        }<br>        <br>        print(&quot;Close&quot;)<br>        <br>        return &quot;My name is \(name)&quot;<br>        <br>    }<br><br>print(testFunction(name: &quot;John&quot;))<br>// Output:<br>// Start<br>// Close<br>// Third deferr<br>// Second defer<br>// First defer<br>// My name is John</pre><p><strong><em>7. What are Variadic Functions in Swift?</em></strong></p><p><em>Ans - In Swift, </em><strong><em>variadic functions</em></strong><em> are functions that can accept a variable number of arguments of the same type. This allows you to pass any number of values to a function without having to specify each one individually. The variadic parameter is represented by an ellipsis (</em><em>...) after the type, and inside the function, it is treated as an array.</em></p><pre>func greetPeople(greeting: String, names: String...) {<br>    for name in names {<br>        print(&quot;\(greeting), \(name)!&quot;)<br>    }<br>}<br><br>greetPeople(greeting: &quot;Hello&quot;, names: &quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;)<br>// Output:<br>// Hello, Alice!<br>// Hello, Bob!<br>// Hello, Charlie!</pre><p><strong><em>8. What are Control Flow in Swift ? </em></strong><strong><em>fallthrough </em></strong><strong><em>VS </em></strong><strong><em>continue </em></strong><strong><em>VS </em></strong><strong><em>break </em></strong><strong><em>VS </em></strong><strong><em>return ?</em></strong></p><p>Ans -<em> In Swift, </em><strong><em>control flow</em></strong><em> refers to the way in which a program’s execution is directed, based on conditions or loops. Swift provides several mechanisms to control the flow of execution, allowing you to handle different logic paths, repeat certain actions, and break or exit loops as needed. These mechanisms include conditional statements, loops, and control statements for handling exceptions or early exits.</em></p><p><em>Types of Control Flow in Swift:</em></p><ul><li><strong><em>Conditional statements:</em></strong><em> </em><em>if,</em><em>else if, </em><em>guard, </em><em>switch</em></li><li><strong><em>Loops:</em></strong><em> </em><em>for-in, </em><em>while, </em><em>repeat-while</em></li><li><strong><em>Flow control:</em></strong><em> </em><em>break, </em><em>continue</em></li></ul><p><em>In Swift, the control flow statements </em><strong><em>fallthrough</em></strong><em>, </em><strong><em>break</em></strong><em>, </em><strong><em>return</em></strong><em>, and </em><strong><em>continue</em></strong><em> are used to control the flow of execution in different contexts (loops, functions, and switch statements)</em></p><ul><li><strong><em>fallthrough</em></strong><em>: Specific to </em><em>switch statements that allows execution to continue to the next case in </em><em>switch.</em></li></ul><pre>let number = 2<br><br>switch number {<br>case 1:<br>    print(&quot;One&quot;)<br>case 2:<br>    print(&quot;Two&quot;)<br>    fallthrough  // Fallthrough to the next case<br>case 3:<br>    print(&quot;Three&quot;)<br>default:<br>    print(&quot;Other&quot;)<br>}</pre><ul><li><strong><em>break</em></strong><em>: Exits the loop or </em><em>switch statement immediately, terminating further execution.</em></li></ul><pre>for i in 1...5 {<br>    if i == 3 {<br>        break  // Exit the loop when i equals 3<br>    }<br>    print(i)<br>}</pre><ul><li><strong><em>return</em></strong><em>: Exits a function and optionally returns a value. It’s used when you want to end the function’s execution and give back control to the caller.</em></li><li><strong><em>continue</em></strong><em>: Skips the current iteration of the loop and moves to the next one.</em></li></ul><pre>for i in 1...5 {<br>    if i == 3 {<br>        continue  // Skip printing when i is 3<br>    }<br>    print(i)<br>}</pre><p><strong><em>Some Syntax of Switch Cases:</em></strong></p><ul><li><strong><em>Multiple conditions in one case</em></strong><em>: Comma-separated values.</em></li></ul><pre>let letter = &quot;a&quot;<br><br>switch letter {<br>case &quot;a&quot;, &quot;e&quot;, &quot;i&quot;, &quot;o&quot;, &quot;u&quot;:<br>    print(&quot;Vowel&quot;)<br>default:<br>    print(&quot;Consonant&quot;)<br>}</pre><ul><li><strong><em>Range matching</em></strong><em>: Using </em><em>... (closed range) and </em><em>..&lt; (half-open range).</em></li></ul><pre>let age = 25<br><br>switch age {<br>case 0..&lt;13:<br>    print(&quot;Child&quot;)<br>case 13..&lt;20:<br>    print(&quot;Teenager&quot;)<br>case 20...:<br>    print(&quot;Adult&quot;)<br>default:<br>    print(&quot;Unknown age&quot;)<br>}</pre><ul><li><strong><em>Tuple matching</em></strong><em>: Matching multiple values at once.</em></li></ul><pre>let coordinates = (x: 3, y: 5)<br><br>switch coordinates {<br>case (0, 0):<br>    print(&quot;Origin&quot;)<br>case (let x, 0):<br>    print(&quot;On the x-axis at \(x)&quot;)<br>case (0, let y):<br>    print(&quot;On the y-axis at \(y)&quot;)<br>case let (x, y):<br>    print(&quot;Coordinates: (\(x), \(y))&quot;)<br>}</pre><ul><li><strong><em>Where clause</em></strong><em>: Additional condition after a case.</em></li></ul><pre>let number = 42<br><br>switch number {<br>case let x where x % 2 == 0:<br>    print(&quot;\(x) is an even number&quot;)<br>case let x where x % 2 != 0:<br>    print(&quot;\(x) is an odd number&quot;)<br>default:<br>    print(&quot;Unknown&quot;)<br>}</pre><ul><li><strong><em>Value binding</em></strong><em>: Extract values from the matched pattern.</em></li></ul><pre>let point = (x: 10, y: 20)<br><br>switch point {<br>case (let x, let y):<br>    print(&quot;Point is at (\(x), \(y))&quot;)<br>} <br>// OR<br><br>switch point {<br>case (x, y):<br>    print(&quot;Point is at (\(x), \(y))&quot;)<br>}</pre><ul><li><strong><em>Complex pattern matching</em></strong><em>: Using combinations of patterns for more detailed matching.</em></li></ul><pre>let value = 30<br><br>switch value {<br>case 1...10:<br>    print(&quot;Between 1 and 10&quot;)<br>case 11..&lt;20:<br>    print(&quot;Between 11 and 19&quot;)<br>case 20...30:<br>    print(&quot;Between 20 and 30&quot;)<br>case 31...:<br>    print(&quot;Greater than 30&quot;)<br>default:<br>    print(&quot;Unknown&quot;)<br>}</pre><p><strong><em>9. What is Auto Layout in iOS? What are difference between Content hugging and content compressing priority in Xcode?</em></strong></p><p><em>Ans - Auto Layout is a powerful and flexible layout system used in iOS development to create user interfaces that adapt to different screen sizes, orientations, and device types (iPhone, iPad, etc.). It allows developers to define relationships between UI elements, rather than manually specifying their positions and sizes. The goal is to build adaptive, responsive interfaces that work seamlessly across different devices and screen sizes without the need for constant adjustments.</em></p><p><em>Auto Layout works by applying </em><strong><em>constraints</em></strong><em> that describe how views (UI elements like buttons, labels, images, etc.) should be positioned, sized, and aligned relative to each other or to their parent views.</em></p><p><strong><em>Advantage of Auto Layout</em></strong><em>: </em><em>Responsive Design , </em><em>Universal support , </em><em>Simplified UI design ,</em></p><p><em>In Xcode’s Auto Layout, </em><strong><em>Content Hugging</em></strong><em> and </em><strong><em>Content Compression</em></strong><em> priorities are key concepts that help define how views behave when the layout constraints are ambiguous or when there’s extra space available. Here’s a breakdown of each:</em></p><ul><li><em>If you want the labels to </em><strong><em>stay as small as possible</em></strong><em>, you can assign them a </em><strong><em>high content hugging priority</em></strong><em> (so they won’t stretch beyond their content size).</em></li><li><em>If you want the button to </em><strong><em>shrink when space is tight</em></strong><em>, you can assign it a </em><strong><em>high content compression priority</em></strong><em> (so it will shrink if the stack view doesn’t have enough space).</em></li></ul><p><strong><em>10. What is @IBDesignable in Swift? Difference between @IBDesinable &amp; @IBInspectable in Swift?</em></strong></p><p><em>Ans - In Swift, both </em><em>@IBDesignable and </em><em>@IBInspectable are used to enhance the design-time experience in Interface Builder (IB) by allowing customization of UI elements in the Interface Builder itself. However, they serve different purposes.</em></p><ul><li><strong><em>@IBDesignable</em></strong><em>: Used for custom views to show live rendering in Interface Builder.</em></li></ul><pre>@IBDesignable<br>class CustomButton: UIButton {<br>    @IBInspectable var cornerRadius: CGFloat = 0 {<br>        didSet {<br>            layer.cornerRadius = cornerRadius<br>        }<br>    }<br>}</pre><ul><li><strong><em>@IBInspectable</em></strong><em>: Used for individual properties to make them editable in Interface Builder’s inspector.</em></li></ul><pre>@IBDesignable<br>class CustomView: UIView {<br>    @IBInspectable var borderWidth: CGFloat = 2 {<br>        didSet {<br>            layer.borderWidth = borderWidth<br>        }<br>    }<br>    @IBInspectable var borderColor: UIColor = .red {<br>        didSet {<br>            layer.borderColor = borderColor.cgColor<br>        }<br>    }<br>}</pre><p><strong><em>Conclusion</em></strong><em>:</em></p><p><em>In this section, we covered some other iOS Interview questions. In the next part of this series, we will explore additional topics and questions.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07578e44cd94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview Question in Swift Part - 4]]></title>
            <link>https://medium.com/@kavita4310ios/interview-question-in-swift-part-4-1c53b1008f23?source=rss-be027ca4ec13------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c53b1008f23</guid>
            <category><![CDATA[questions-answers]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swi̇ft]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Kavita Chauhan]]></dc:creator>
            <pubDate>Tue, 31 Dec 2024 18:15:55 GMT</pubDate>
            <atom:updated>2024-12-31T18:15:55.727Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this part, we will cover some other iOS Interview questions that are commonly asked by interviewers during job interviews. Let’s get started.</em></p><ol><li><strong><em>What is Retain Cycle in Swift? How we can create and avoid Retain Cycle?</em></strong></li></ol><p><em>Ans - A </em><strong><em>retain cycle</em></strong><em> (</em><strong><em>strong reference cycle</em></strong><em>) occurs when two or more objects hold strong references to each other, preventing them from being deallocated from memory when they are no longer needed. This can lead to </em><strong><em>memory leaks</em></strong><em> because the objects are not released by the reference counting system (ARC — Automatic Reference Counting) and in result memory leaks and poor performance over time. Closures can also experience retain cycle.</em></p><pre>class A {<br>    var b: B?<br>    init() {<br>        print(&quot;A initialized&quot;)<br>    }<br>    deinit {<br>        print(&quot;A deinitialized&quot;)<br>    }<br>}<br><br>class B {<br>    var a: A?<br>    init() {<br>        print(&quot;B initialized&quot;)<br>    }<br>    deinit {<br>        print(&quot;B deinitialized&quot;)<br>    }<br>}<br><br>var objectA: A? = A()<br>var objectB: B? = B()<br><br>objectA?.b = objectB<br>objectB?.a = objectA<br><br>// At this point, both A and B are holding strong references to each other.</pre><p><em>To prevent retain cycles, we can break the strong reference cycle by using </em><strong><em>weak</em></strong><em> or </em><strong><em>unowned</em></strong><em> references. These references do not increase the reference count, allowing objects to be deallocated properly from memory.</em></p><p><em>A </em><strong><em>weak reference</em></strong><em> is a reference that does not retain the object. When the object it references is deallocated, the weak reference automatically becomes </em><em>nil. </em><strong><em>weak </em></strong><em>always use with var keywords.</em></p><pre>class A {<br>    var b: B?<br>    init() {<br>        print(&quot;A initialized&quot;)<br>    }<br>    deinit {<br>        print(&quot;A deinitialized&quot;)<br>    }<br>}<br><br>class B {<br>    weak var a: A?  // weak reference to prevent retain cycle<br>    init() {<br>        print(&quot;B initialized&quot;)<br>    }<br>    deinit {<br>        print(&quot;B deinitialized&quot;)<br>    }<br>}<br><br>var objectA: A? = A()<br>var objectB: B? = B()<br><br>objectA?.b = objectB<br>objectB?.a = objectA<br><br>// Now the retain cycle is broken, and A and B can be deallocated correctly.</pre><p><em>An </em><strong><em>unowned reference</em></strong><em> is similar to a weak reference, but it is used when one object references another object, and the referenced object should never become </em><em>nil while the referencing object exists. If the object being referenced is deallocated, the unowned reference will cause a runtime crash if accessed, which is why it should be used only in cases where you are sure that the referenced object will always outlive the referring object.</em></p><pre>class A {<br>    var b: B?<br>    init() {<br>        print(&quot;A initialized&quot;)<br>    }<br>    deinit {<br>        print(&quot;A deinitialized&quot;)<br>    }<br>}<br><br>class B {<br>    unowned var a: A  // unowned reference to prevent retain cycle<br>    init(a: A) {<br>        self.a = a<br>        print(&quot;B initialized&quot;)<br>    }<br>    deinit {<br>        print(&quot;B deinitialized&quot;)<br>    }<br>}<br><br>var objectA: A? = A()<br>var objectB: B? = B(a: objectA!)<br><br>objectA?.b = objectB<br><br>// No retain cycle. A and B are deallocated correctly.</pre><ul><li><strong><em>Weak references</em></strong><em> can become </em><em>nil when the object it refers to is deallocated.</em></li><li><strong><em>Unowned references</em></strong><em> never become </em><em>nil. They assume the object will not be deallocated before the reference.</em></li></ul><p><strong><em>2. What is Type Casting? How many way of type casting in Swift?</em></strong></p><p><em>Ans - </em><strong><em>Type casting</em></strong><em> in Swift refers to the process of checking and converting the type of an object or variable to another type. This is particularly useful when you work with class hierarchies, protocols, or collections of objects with different types. Swift provides </em><strong><em>upcasting</em></strong><em> (converting to a superclass or protocol) and </em><strong><em>downcasting</em></strong><em> (converting to a subclass or more specific type).</em></p><p><em>There are </em><strong><em>three main ways</em></strong><em> to perform type casting in Swift:</em></p><ul><li><strong><em>Upcasting</em></strong><em> (</em><em>as) is always safe because every subclass is also an instance of its superclass.</em></li><li><strong><em>Optional downcasting</em></strong><em> (</em><em>as?) is used when you&#39;re not sure about the type, and it safely returns </em><em>nil if the cast fails.</em></li><li><strong><em>Forced downcasting</em></strong><em> (</em><em>as!) should be used when you&#39;re absolutely sure the type conversion will succeed, but be aware that it can crash the program if the cast fails.</em></li></ul><p><strong><em>3. Difference between if-let and guard-let in Swift?</em></strong></p><p><em>Ans - In Swift, both </em><em>if-let and </em><em>guard-let are used for optional binding, which allows you to safely unwrap optionals. However, they serve different purposes and have distinct use cases.</em></p><ul><li><strong>if-let</strong> is used to conditionally unwrap an optional and handle both the nil and non-nilcases, typically within the same scope.</li><li><strong>guard-let</strong> is used when a certain condition (like an optional being non-nil) before continuing execution, and if the condition is not met, it exit early from the current scope (e.g., return or throw).</li></ul><p><strong><em>4. What are Initializer’s? How many types of Initializer’s in Swift?</em></strong></p><p>Ans - <strong><em>Initializer’s</em></strong> <em>is a special method used to set up an instance of a class, struct, or enum. Initializers allow to initialize the properties of an instance with appropriate values when the object is created. Every time we create a new instance of a type, an initializer is called to set up the initial state of the object.</em></p><p><em>Swift supports </em><strong><em>three main types of initializers</em></strong><em>:</em></p><ul><li><strong><em>Designated Initializer</em></strong><em>: Use when you need to fully initialize an object, especially when creating a custom class, struct, or enum with required properties.</em></li><li><strong><em>Convenience Initializer</em></strong><em>: Use for simplifying initialization by providing default or simplified values, often in subclasses to call the superclass’s designated initializer.</em></li><li><strong><em>Failable Initializer</em></strong><em>: Use when there’s a chance that an object might not be created due to invalid parameters or conditions, returning </em><em>nil if it fails.</em></li></ul><pre>class Vehicle {<br>    var numberOfWheels: Int<br>    var color: String<br>    <br>    // Designated initializer<br>    init(numberOfWheels: Int, color: String) {<br>        self.numberOfWheels = numberOfWheels<br>        self.color = color<br>    }<br>    <br>    // Convenience initializer<br>    convenience init(color: String) {<br>        self.init(numberOfWheels: 4, color: color)  // Calling the designated initializer<br>    }<br>}<br><br>let bike = Vehicle(color: &quot;Blue&quot;)<br><br><br>class Person {<br>    var name: String<br>    var age: Int<br>    <br>    // Failable initializer<br>    init?(name: String, age: Int) {<br>        if age &lt; 0 {<br>            return nil  // Return nil if age is invalid<br>        }<br>        self.name = name<br>        self.age = age<br>    }<br>}<br><br>let validPerson = Person(name: &quot;John&quot;, age: 30)  // Valid initialization<br>let invalidPerson = Person(name: &quot;Jane&quot;, age: -5)  // Fails, returns nil</pre><p><strong><em>5. What are the difference between Float and CGFloat in Swift?</em></strong></p><p><em>Ans - In Swift, </em><em>Float and </em><em>CGFloat are both data types used to represent floating-point numbers, but they differ primarily in their size, precision, and intended use, especially when working with Apple frameworks like UIKit and SwiftUI.</em></p><p><strong><em>Float</em></strong><em>:</em><em>Float is a 32-bit floating-point number.</em></p><ul><li><em>It has a smaller range and lower precision compared to </em><em>Double.</em></li><li><em>It provides roughly 6 decimal digits of precision.</em></li></ul><p><strong><em>CGFloat</em></strong><em>:</em><em>CGFloat is a platform-dependent type and is used primarily for graphics-related operations in iOS, macOS, and other Apple platforms.</em></p><ul><li><em>On </em><strong><em>32-bit</em></strong><em> platforms, </em><em>CGFloat is equivalent to </em><em>Float (32-bit).</em></li><li><em>On </em><strong><em>64-bit</em></strong><em> platforms, </em><em>CGFloat is equivalent to </em><em>Double (64-bit).</em></li><li><em>This means the precision and size of </em><em>CGFloat can vary depending on the architecture of the device (i.e., 32-bit vs. 64-bit).</em></li><li><em>In general, </em><em>CGFloat provides better precision (similar to </em><em>Double on 64-bit devices).</em></li><li><em>When working with graphics, we often need to use </em><em>CGFloat. For example, when working with </em><em>CGRect, </em><em>CGPoint, or </em><em>CGSize in Core Graphics, the values of these structures are </em><em>CGFloat.</em></li></ul><p><strong><em>6. What are the difference between Frame and Bounds of View in Swift?</em></strong></p><p><em>Ans - The </em><strong><em>frame</em></strong><em> and </em><strong><em>bounds</em></strong><em> of a view in Swift both describe the size and position of the view, but they are used in different contexts.</em></p><ul><li><strong><em>Frame</em></strong><em>: Relative to the superview’s coordinate system.</em></li><li><em>Used for positioning and laying out views in relation to their superviews.</em></li></ul><pre>view.frame = CGRect(x: 50, y: 100, width: 200, height: 150)<br>//This sets the view&#39;s position at (50, 100) in the superview&#39;s coordinate system, with a size of 200x150.</pre><ul><li><strong><em>Bounds</em></strong><em>: Relative to the view’s own coordinate system.</em></li><li><em>Used to get view’s size and internal content layout in its own coordinate system.</em></li></ul><pre>view.bounds = CGRect(x: 0, y: 0, width: 200, height: 150)<br>//This sets the view&#39;s internal content size to 200x150, and the origin is typically (0, 0).</pre><p><strong><em>7. Cocoa </em></strong><strong><em>VS CocoaTouch </em></strong><strong><em>VS CocoaPods in iOS?</em></strong></p><p><em>Ans - The </em><strong><em>Cocoa</em></strong><em> and </em><strong><em>Cocoa Touch</em></strong><em> refer to two different frameworks used in the development of applications for Apple platforms, but they are closely related. The main difference lies in the platform and the specific libraries and tools they provide, while Cocoa pods is a dependency manager that simplifies the integration of third party library.</em></p><ul><li><strong><em>Cocoa:</em></strong><em> is the native </em><strong><em>object-oriented application framework</em></strong><em> for developing macOS applications.</em></li><li><em>It provides a wide range of tools for building macOS desktop applications, including user interface elements, event handling, and application management.</em></li><li><strong><em>Cocoa Touch:</em></strong><em> is the framework used for developing applications for </em><strong><em>iOS</em></strong><em>, </em><strong><em>iPadOS</em></strong><em>, </em><strong><em>tvOS</em></strong><em>, and </em><strong><em>watchOS</em></strong><em>.</em></li><li><em>Cocoa Touch is essentially an adaptation of Cocoa for the touch-based, mobile-oriented environments of iOS devices, with features suited to touch gestures, accelerometer inputs, and multitouch capabilities.</em></li></ul><p><strong><em>8. Does extension support Stored properties in Swift?</em></strong></p><p><em>Ans - Extensions allow to add new functionality to an existing class, structure, or enumeration, such as new methods, computed properties, or conformances to protocols. However, extensions doesn’t support </em><strong><em>stored properties</em></strong><em>.</em></p><p><em>In an extension, we can add:</em><strong><em>Computed properties</em></strong><em> (which do not require storage), </em><strong><em>Methods, Initializers</em></strong><em> (in some cases, if not already implemented), </em><strong><em>Protocol conformance</em></strong><em>, </em><strong><em>Nested types</em></strong><em>.</em></p><pre>class Person {<br>    var firstName: String<br>    var lastName: String<br><br>    init(firstName: String, lastName: String) {<br>        self.firstName = firstName<br>        self.lastName = lastName<br>    }<br>}<br><br>extension Person {<br>    var fullName: String {<br>        return &quot;\(firstName) \(lastName)&quot;<br>    }<br>}<br><br>let person = Person(firstName: &quot;John&quot;, lastName: &quot;Doe&quot;)<br>print(person.fullName)  // Output: John Doe</pre><p><strong><em>9. What are tuples? How tuples are different from array in Swift?</em></strong></p><p><em>Ans - In Swift, </em><strong><em>tuples</em></strong><em> are a flexible, lightweight way to group multiple values of different types into a single compound value. It is used to store different data type. Tuples are often used for returning multiple values from a function or temporarily grouping related data. The size of a tuple is </em><strong><em>fixed </em></strong><em>we cannot be changed after creation, while </em><strong><em>array</em></strong><em> is used to store an </em><strong><em>ordered collection</em></strong><em> of elements that are of the </em><strong><em>same type</em></strong><em>, Arrays can be resized and modified.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3dGoRJhOM2fOwiIon-Egcw.png" /></figure><p><strong><em>10. Difference between self and Self keyword in Swift?</em></strong></p><p><em>Ans - In Swift, the terms </em><em>self and </em><em>Self are both used within the context of types and instances, but they refer to different things and are used in distinct situations.</em></p><ul><li><strong><em>self :-Refers to the current instance</em></strong><em> of a class, struct, or enum.</em></li><li><em>It is used to refer to the </em><strong><em>instance</em></strong><em> of the type within instance methods, closures, or other contexts where the instance itself is being referenced.</em></li><li><em>It is </em><strong><em>always lowercase</em></strong><em> and is typically used inside instance methods to refer to the object or struct that the method is being called on.</em></li></ul><pre>class Person {<br>    var name: String<br><br>    init(name: String) {<br>        self.name = name <br>    }<br><br>    func greet() {<br>        print(&quot;Hello, my name is \(self.name).&quot;) // `self` refers to the instance of `Person`<br>    }<br>}<br><br>let person = Person(name: &quot;John&quot;)<br>person.greet()  // Output: Hello, my name is John.</pre><ul><li><strong><em>Self :-Refers to the type itself</em></strong><em>, not an instance of the type. Specifically, it refers to the type within the context of a class, struct, enum, or protocol.</em></li><li><em>It is used to refer to the </em><strong><em>type</em></strong><em> of the object (class/struct/enum) and is particularly useful when working with type methods, type properties, or generic types.</em></li><li><em>In </em><strong><em>protocols</em></strong><em>, </em><em>Self is used to refer to the type that conforms to the protocol.</em></li></ul><pre>class Animal {<br>    class func description() -&gt; String {<br>        return &quot;An animal&quot;<br>    }<br><br>    func descriptionInstance() -&gt; String {<br>        return &quot;This is an instance of \(Self.self)&quot;<br>    }<br>}<br><br>let animal = Animal()<br>print(animal.descriptionInstance())  // Output: This is an instance of Animal</pre><p><strong><em>Conclusion</em></strong><em>:</em></p><p><em>In this section, we covered some fundamental iOS Swift questions. In the next part of this series, we will explore additional topics and questions.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c53b1008f23" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview Question in Swift Part - 3]]></title>
            <link>https://medium.com/@kavita4310ios/interview-question-in-swift-part-3-2bb5b7d24670?source=rss-be027ca4ec13------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bb5b7d24670</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[preparation]]></category>
            <category><![CDATA[questions-answers]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Kavita Chauhan]]></dc:creator>
            <pubDate>Sun, 29 Dec 2024 13:31:57 GMT</pubDate>
            <atom:updated>2024-12-29T13:44:16.334Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>In this part, we will cover some other iOS Interview questions that are commonly asked by interviewers during job interviews. Let’s get started.</blockquote><p><em>1.</em> <strong><em>Protocol </em></strong><strong>VS <em>Specific Build in Protocol</em></strong><em> </em><strong><em>VS</em></strong><em> </em><strong><em>Protocol-Oriented Programming</em></strong><em> (POP)</em><strong><em> in Swift</em></strong><em>?</em></p><p><em>Ans - Protocols are used to define a common interface that can be adopted by classes, structs, and enums. It ensures that these types conform to a specific set of methods, properties, or requirements.</em></p><pre>protocol Animal {<br>    var name: String { get set }<br>    func makeSound()<br>}<br><br>class Dog: Animal {<br>    var name: String<br>    init(name: String) {<br>        self.name = name<br>    }<br>    <br>    func makeSound() {<br>        print(&quot;Woof!&quot;)<br>    }<br>}</pre><p><em>These are some of the </em><strong><em>built-in protocols</em></strong><em> that have specialized behaviour&#39;s.</em></p><ul><li><strong><em>Codable</em></strong><em>: For encoding/decoding objects to/from an external format.</em></li><li><strong><em>Encodable</em></strong><em>: allows the object to be converted into a format like JSON.</em></li><li><strong><em>Decodable</em></strong><em>: allows the object to be created from an external format (like JSON).</em></li><li><strong><em>Equatable</em></strong><em>: For checking equality of instances (</em><em>==).</em></li><li><strong><em>Comparable</em></strong><em>: For comparing instances (</em><em>&lt;, </em><em>&gt;, etc.).</em></li><li><strong><em>Hashable</em></strong><em>: For generating a unique hash value of an instance.</em></li><li><strong><em>Identifiable</em></strong><em>: For providing a unique identifier (</em><em>id property).</em></li></ul><p><strong><em>Protocol-Oriented Programming</em></strong><em>, a programming paradigm in Swift that emphasises the use of protocols rather than inheritance (i.e., using classes and subclasses) to define shared behavior. POP encourages you to design software around protocols and their extensions rather than focusing on classes or inheritance hierarchies.</em></p><p><em>In summary:</em></p><ul><li><strong><em>Protocols in Swift</em></strong><em> define a blueprint that can be adopted by any type (class, struct, enum).</em></li><li><strong><em>Built-in Protocols</em></strong><em> , Built-in protocols that provide specific functionality to types that conform to them.</em></li><li><strong><em>Protocol-Oriented Programming (POP)</em></strong><em> is a paradigm that encourages the use of protocols as a primary design tool to ensure flexibility and reuse, but it’s not a separate category of protocols.</em></li></ul><p><strong><em>2. What are collections in Swift, and what are their types?</em></strong></p><p><em>Ans - Collections in Swift are used to store and organize data efficiently. There are three primary types of collections in Swift for managing data: arrays, dictionaries, and sets.</em></p><ul><li><strong><em>Arrays</em></strong><em>: Ordered collections of values that can be accessed randomly. Arrays are homogenous by default, meaning they can only contain elements of the same type.</em></li><li><strong><em>Sets</em></strong><em>: Unordered collections of unique values.</em></li><li><strong><em>Dictionaries</em></strong><em>: Unordered collections of key-value pairs.</em></li></ul><p><strong><em>3. What are Generic’s in Swift, How Generic’s differ form Opaque Type and Associated Type?</em></strong></p><p><em>Ans - </em><strong><em>Generics</em></strong><em> in Swift is a way to write flexible and reusable code that can be work with any type,</em></p><pre>func printElement&lt;T&gt;(_ element: T) {<br>    print(element)<br>}<br><br>printElement(42)        // T is Int<br>printElement(&quot;Hello&quot;)   // T is String</pre><p><strong><em>Opaque types</em></strong><em> hide the specific type of a value while still ensuring that the value conforms to a protocol. The key point is that you don’t know the exact type, but you know that it conforms to a specific protocol.</em></p><pre>protocol Animal {<br>    func speak() -&gt; String<br>}<br><br>struct Dog: Animal {<br>    func speak() -&gt; String {<br>        return &quot;Woof!&quot;<br>    }<br>}<br><br>func getAnimal() -&gt; some Animal {<br>    return Dog()  // Returning an opaque type that conforms to Animal<br>}<br><br>let animal = getAnimal()<br>print(animal.speak())  // &quot;Woof!&quot;</pre><p><strong><em>Associated Types </em></strong><em>is used to</em><strong><em> </em></strong><em>define flexible protocols that can work with different types, allowing the concrete type to specify what type will be used</em></p><pre>// Define the protocol with an associated type<br>protocol Associate {<br>    associatedtype MyType<br>    func sumOf(x: MyType, y: MyType) -&gt; MyType<br>}<br><br>// First class that conforms to the Associate protocol and uses Int for MyType<br>class FirstClass: Associate {<br>    <br>    typealias MyType = Int  // Specify MyType as Int<br>    <br>    func sumOf(x: Int, y: Int) -&gt; Int {<br>        return x + y<br>    }<br>}<br><br>// Second class that conforms to the Associate protocol and uses Float for MyType<br>class SecondClass: Associate {<br>    <br>    typealias MyType = Float  // Specify MyType as Float<br>    <br>    func sumOf(x: Float, y: Float) -&gt; Float {<br>        return x + y<br>    }<br>}<br><br>// Usage example:<br><br>// Create an instance of FirstClass and calculate sum of Int values<br>let first = FirstClass()<br>let intSum = first.sumOf(x: 10, y: 20)<br>print(&quot;Sum of Int values: \(intSum)&quot;)  // Output: 30<br><br>// Create an instance of SecondClass and calculate sum of Float values<br>let second = SecondClass()<br>let floatSum = second.sumOf(x: 10.5, y: 20.3)<br>print(&quot;Sum of Float values: \(floatSum)&quot;)  // Output: 30.8</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LNfyZ2mKM-zEjohQ3hIDHQ.png" /></figure><p><strong><em>4. What are Enumerations in Swift and their Types?</em></strong></p><p><em>Ans - In Swift, </em><strong><em>enumerations</em></strong><em> referred as </em><strong><em>enums</em></strong><em> are a powerful and flexible way to define a type that can represent a set of related values. Enums allow you to group together a set of related values, and you can associate additional data and behavior with those values. Enums are value type.</em></p><p><em>Enums in Swift are </em><strong><em>type-safe</em></strong><em>, which means that they can only represent one of the defined values at a time, ensuring that your code handles cases explicitly and safely.</em></p><p><strong><em>Types of Enumerations in Swift</em></strong><em>:</em></p><p><em>Swift provides different types of enumerations, each offering different features and capabilities:</em></p><ol><li><strong><em>Basic Enums</em></strong></li><li><strong><em>Enums with Associated Values</em></strong></li><li><strong><em>Enums with Raw Values</em></strong></li><li><strong><em>Recursive Enums</em></strong></li></ol><pre>// Basic Enums<br>enum Weekday {<br>    case monday, tuesday, wednesday, thursday, friday, saturday, sunday<br>}<br>let today = Weekday.monday<br><br>// Enums with Associated Values<br>enum Result {<br>    case success(String)<br>    case failure(Int)<br>}<br><br>let successResult = Result.success(&quot;Operation completed successfully&quot;)<br>let failureResult = Result.failure(404)<br><br>switch successResult {<br>case .success(let message):<br>    print(message) <br>case .failure(let errorCode):<br>    print(&quot;Error code: \(errorCode)&quot;)<br>}<br><br>// Enums with Raw Values<br>enum Day: Int {<br>    case monday = 1<br>    case tuesday = 2<br>    case wednesday = 3<br>    case thursday = 4<br>    case friday = 5<br>    case saturday = 6<br>    case sunday = 7<br>}<br><br>let day = Day(rawValue: 3)<br>print(day)<br><br>// Recursive Enums<br>enum LinkedList {<br>    case empty<br>    case node(value: Int, next: LinkedList)<br>}<br><br>indirect enum LinkedList {<br>    case empty<br>    case node(value: Int, next: LinkedList)<br>}<br><br>let list = LinkedList.node(value: 1, next: .node(value: 2, next: .empty))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A35EibOdJzhO5JcHMPbE-Q.png" /></figure><p><strong><em>5. What are Difference between Any and AnyObject in Swift?</em></strong></p><p><em>Ans - In Swift, both </em><em>Any and </em><em>AnyObject are types that allow to work with any type, but they are used in different contexts and have distinct behaviors.</em></p><p><strong><em>Any</em></strong><em> is a type that can represent </em><strong><em>any type of value</em></strong><em>, including both </em><strong><em>value types</em></strong><em> (like </em><em>Int, </em><em>String, </em><em>Double, etc.) and </em><strong><em>reference types</em></strong><em> (like classes and objects).</em></p><p>Value types are types that are copied when they are assigned to a new variable or passed into a function. These include:</p><ul><li><strong><em>Basic data types</em></strong><em> (e.g., </em><em>Int, </em><em>String, </em><em>Double)</em></li><li><strong><em>Structs</em></strong></li><li><strong><em>Enums</em></strong></li></ul><p><em>When you assign a value type to a variable or pass it around, the actual value is copied, not the reference.</em></p><pre>var integer: Any = 42         // Integer is a value type<br>var string: Any = &quot;Hello&quot;     // String is a value type<br>var double: Any = 3.14        // Double is a value type</pre><p><em>Reference types are types where instances are passed by reference. These include:</em></p><ul><li><strong><em>Classes</em></strong></li><li><strong><em>Functions</em></strong><em> (which are closures)</em></li><li><strong><em>Arrays, Dictionaries, Sets</em></strong><em> (which are implemented as reference types internally)</em></li></ul><p><em>When you assign a reference type to a variable or pass it into a function, you are working with a reference to the same instance (not a copy).</em></p><pre>class MyClass {<br>    var name: String<br><br>    init(name: String) {<br>        self.name = name<br>    }<br>}<br><br>var object: Any = MyClass(name: &quot;John&quot;)   // MyClass is a reference type</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jY3PAWZ5aIBhzrJ8XwBHkA.png" /></figure><p><strong><em>AnyObject</em></strong><em> is a type that represents </em><strong><em>any class type</em></strong><em> (i.e., </em><strong><em>instances of classes</em></strong><em>). Unlike </em><em>Any, which can hold </em><strong><em>both value types and reference types</em></strong><em>, </em><em>AnyObject is specifically used to represent </em><strong><em>only reference types</em></strong><em>, that is, </em><strong><em>instances of classes</em></strong><em>.</em></p><pre>class GreetingClass {<br>    func greet() {<br>        print(&quot;Hello!&quot;)<br>    }<br>}<br><br>var object: AnyObject = GreetingClass()<br><br>// You can call methods on `object` after casting<br>if let myObject = object as? GreetingClass {<br>    myObject.greet() // Outputs &quot;Hello!&quot;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T7MeO4AlI13o46zIgLHnxw.png" /></figure><p><strong><em>6. What are Higher-Order functions in Swift and why they are called higher-order functions?</em></strong></p><p><em>Ans - </em><strong><em>Higher-order functions</em></strong><em> are functions that either </em><strong><em>accept one or more functions as arguments</em></strong><em> or </em><strong><em>return a function as a result</em></strong><em>. They are a fundamental concept in functional programming and help make Swift code more expressive, reusable, and concise.</em></p><p><em>Common higher-order functions in Swift include </em><em>map, </em><em>filter, </em><em>reduce, </em><em>flatMap, and </em><em>sort, which allow you to perform operations on collections in a declarative way. These functions are called </em><strong><em>higher-order</em></strong><em> because they work with other functions as parameters or return values, which makes them a level above traditional functions that work directly with data.</em></p><p><strong><em>7. What are the difference between Alamofire and URL session?</em></strong></p><p><em>Ans - Both </em><strong><em>Alamofire</em></strong><em> and </em><strong><em>URLSession</em></strong><em> are used for making network requests in iOS applications, but they differ in terms of </em><strong><em>ease of use</em></strong><em>, </em><strong><em>features</em></strong><em>, and </em><strong><em>level of abstraction</em></strong><em>. Below is a comparison between Alamofire and URLSession in terms of various aspects:</em></p><p><strong><em>Alamofire</em></strong><em>:</em></p><ul><li><strong><em>Alamofire</em></strong><em> is a popular third-party networking library written in Swift, built on top of </em><strong><em>URLSession</em></strong><em>.</em></li><li><em>It provides an </em><strong><em>easier and more developer-friendly interface</em></strong><em> for handling network requests, especially when dealing with JSON, authentication, and complex request/response management.</em></li><li><em>It wraps around </em><em>URLSession to offer higher-level abstractions, making common network tasks (like downloading, uploading, and parsing JSON) simpler.</em></li></ul><pre>        AF.request(url, method: .get, encoding: JSONEncoding.default).response { response in<br>                switch response.result {<br>                case .success(let value):<br>                    print(&quot;Response JSON: \(value)&quot;)<br>                case .failure(let error):<br>                    print(&quot;Error: \(error)&quot;)<br>                }<br>            }</pre><p><strong><em>URLSession</em></strong><em>:</em></p><ul><li><strong><em>URLSession</em></strong><em> is a </em><strong><em>native API</em></strong><em> provided by Apple for handling HTTP requests and other networking tasks.</em></li><li><em>It is part of the </em><strong><em>Foundation framework</em></strong><em> and is a lower-level API compared to Alamofire.</em></li><li><em>It provides more flexibility and control but requires more manual setup and handling of tasks.</em></li></ul><pre> var request = URLRequest(url: url)<br>        request.httpMethod = &quot;GET&quot;<br>let task = URLSession.shared.dataTask(with: request) { (data, response, error) in<br>    if let data = data {<br>      // handle Data   <br>    }<br>}<br>task.resume()</pre><p><strong><em>8. What are the difference between JSON Serialization and JSON Decoder in Swift, If JSON Serialization was exits then why JSON decoder come into the picture?</em></strong></p><p><em>Ans - In Swift, </em><strong><em>JSON Serialization</em></strong><em> and </em><strong><em>JSON Decoding</em></strong><em> are two different concepts that deal with converting data between Swift objects and JSON (JavaScript Object Notation) format. However, they serve slightly different purposes, and different methods .</em></p><p><em>JSON </em><strong><em>Serialization</em></strong><em> refers to the process of converting a </em><strong><em>Swift object</em></strong><em> (such as a dictionary, array, or custom model) into a </em><strong><em>JSON format</em></strong><em> (usually a string or data). It essentially means turning </em><strong><em>Swift data into JSON</em></strong><em> so that it can be sent over the network or saved into files in a standard format.</em></p><p><em>JSON </em><strong><em>Decoding</em></strong><em> refers to the process of converting </em><strong><em>JSON data</em></strong><em> (either in string or binary format) into </em><strong><em>Swift objects</em></strong><em>. This is typically used when you are receiving JSON data from an API and need to convert it into a usable Swift object like a dictionary, array, or a custom struct/class.</em></p><p><em>In summary:</em></p><ul><li><strong><em>JSON Serialization</em></strong><em>: Converts Swift objects (e.g., dictionaries, arrays, custom structs) into JSON format (usually </em><em>Data). Used for sending data.</em></li><li><strong><em>JSON Decoding</em></strong><em>: Converts JSON data into Swift objects. It makes it easy to parse and handle structured data from JSON responses, especially when combined with </em><em>Codable.</em></li><li><strong><em>Why Decoding Came Into the Front</em></strong><em>: With the introduction of the </em><em>Codable protocol, </em><strong><em>JSON decoding</em></strong><em> has become much easier and more powerful in Swift. </em><em>JSONDecoder allows you to map JSON directly to </em><strong><em>typed Swift objects</em></strong><em> with minimal boilerplate code, making it the preferred method for most use cases involving JSON.</em></li></ul><p><strong><em>9. What are the </em></strong><em>Error </em><strong><em>protocol, and what are the different ways to handle Errors in Swift?</em></strong></p><p><em>Ans - The </em><strong><em>Error protocol</em></strong><em> in Swift is a special protocol that any type can conform to if it needs to be used as an error in Swift&#39;s error handling system. It doesn&#39;t require any properties or methods, It simply marks a type as an </em><strong><em>error type</em></strong><em> that can be thrown or caught.</em></p><ul><li><strong><em>Throwing Errors</em></strong><em>: Functions that can throw errors are marked with the </em><em>throws keyword, and errors are thrown using the </em><em>throw keyword.</em></li><li><strong><em>Error Propagation</em></strong><em>: Errors can be propagated up the call stack using </em><em>try, </em><em>try?, or </em><em>try!.</em></li><li><strong><em>do-catch Block</em></strong><em>: This block allows you to catch and handle errors gracefully.</em></li><li><strong><em>Result Type</em></strong><em>: A functional programming approach to handling errors using </em><em>.success and </em><em>.failure.</em></li><li><strong><em>Custom Errors</em></strong><em>: You can create custom error types using enums or structs.</em></li></ul><pre>// Custom Error<br>enum NetworkError: Error {<br>    case badURL<br>    case noConnection<br>    case serverError(String)<br>} <br><br>// Throwing Error<br>enum MyError: Error {<br>    case invalidInput<br>    case networkUnavailable<br>}<br><br>func performOperation(input: String) throws {<br>    if input.isEmpty {<br>        throw MyError.invalidInput<br>    }<br>    // Perform other operations...<br>}<br><br>// Do-catch Block<br><br>do {<br>    try performOperation(input: &quot;Hello&quot;)<br>} catch MyError.invalidInput {<br>    print(&quot;Invalid input!&quot;)<br>} catch {<br>    print(&quot;An unexpected error occurred: \(error)&quot;)<br>}<br><br>// Error Propagation<br><br>let result = try? performOperation(input: &quot;&quot;)<br>try! performOperation(input: &quot;Valid Input&quot;)<br><br><br>// Result Type<br>enum MyError: Error {<br>    case invalidInput<br>    case networkUnavailable<br>}<br><br>func performOperation(input: String) -&gt; Result&lt;String, MyError&gt; {<br>    if input.isEmpty {<br>        return .failure(.invalidInput)<br>    }<br>    return .success(&quot;Operation successful&quot;)<br>}<br><br>let result = performOperation(input: &quot;&quot;)<br><br>switch result {<br>case .success(let message):<br>    print(message)<br>case .failure(let error):<br>    print(&quot;Error: \(error)&quot;)<br>}</pre><p><strong><em>10. What are the main Difference between HTTP status code 200 and 201 in API response in Swift?</em></strong></p><p><em>Ans - In the context of HTTP status codes, </em><strong><em>200 </em></strong><em>and </em><strong><em>201 </em></strong><em>are both </em><strong><em>successful response codes</em></strong><em>, but they indicate slightly different outcomes for an API request.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzC2MouG2Kel677czDDQDg.png" /></figure><p><strong><em>Conclusion</em></strong><em>:</em></p><p><em>In this section, we covered some fundamental iOS Swift questions. In the next part of this series, we will explore additional topics and questions.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bb5b7d24670" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview Questions in Swift Part — 2]]></title>
            <link>https://medium.com/@kavita4310ios/interview-questions-in-swift-part-2-e0a9f0061fe0?source=rss-be027ca4ec13------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0a9f0061fe0</guid>
            <category><![CDATA[swift-basics]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[basics]]></category>
            <dc:creator><![CDATA[Kavita Chauhan]]></dc:creator>
            <pubDate>Tue, 10 Sep 2024 19:16:07 GMT</pubDate>
            <atom:updated>2024-12-29T13:40:04.241Z</atom:updated>
            <content:encoded><![CDATA[<h3>Interview Questions in Swift Part - 2</h3><blockquote>In this Part, we will learn some other basic questions which is generally asked by interviewer’s during interview. So, Let’s continue.</blockquote><p><strong>1- What is iOS Application Life Cycle. How many stage of iOS Application Life Cycle ?</strong></p><p>Ans - The iOS App life cycle is a continuous series of events that occur between the launch and termination of App. It complete in 6 stage.</p><p>1- didFinishLaunchingWithOptions</p><p>2- applicationWillEnterForeground</p><p>3- applicationDidBecomeActive</p><p>4- applicationWillResignActive</p><p>5- applicationDidEnterBackground</p><p>6- applicationWillTerminate</p><p><strong>2- What is the use of App Delegate life Cycle ?</strong></p><p>Ans - App delegate provide help to know the App current State. iOS Application life cycle depends on App Delegate function. The life cycle delegate provide the control of application. When we work with CoreData then we should use App delegate for creating manage Objects of CoreData.</p><p><strong>3- What is the difference between App Delegate and Scene Delegate ?</strong></p><p>Ans - App delegate handle process life cycle which is launch and terminate. while, Scene delegate handle UI life-cycle which takes responsibility from App delegate like — App foreground and background.</p><p><strong>4- What is the purpose of the method Did Finish Launching with options return type, what will happen returned if value will change ?</strong></p><p>Ans - If user will change the value of return types (<strong>false</strong> from <strong>true) </strong>generally<strong> </strong>then App life cycle will ignore the return value. If there is a URL in launchOptions and you return NO, then the operating system will know that you cannot open the provided URL for some reason.</p><p><strong>5- How many states of iOS Application?</strong></p><p>Ans - The app follow the states every time. App change the states according to triggered events by the user and the system. It complete in 5 stage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*Z1RJFL_XPEKiZvvV6Xhd8g.png" /><figcaption>iOS App States</figcaption></figure><p><strong>6- What is View Controller and their Life Cycle ?</strong></p><p>Ans - A View Controller is a controller that manage single root view, which may itself contain any number of subviews. User Interaction with that view hierarchy are handle by view controller. The view controller life cycle complete mainly in 6 stages.</p><ul><li>loadView()</li><li>viewDidLoad()</li><li>viewWillAppear(_ animated: Bool)</li><li>viewWillLayoutSubviews()</li><li>viewDidLayoutSubviews()</li><li>viewDidAppear(_ animated: Bool)</li><li>viewWillDisappear(_ animated: Bool)</li><li>viewDidDisappear(_ animated: Bool)</li><li>didReceiveMemoryWarning()</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FIXqfNICZ70SeNvJoJWg3A.png" /></figure><p><strong>7- What is the structure of iOS Operating System ?</strong></p><p>Ans - iOS Operating system is a layer based communication. It can’t communicate directly. The layers between the application layer and hardware is help in communication. The lower layer gives basic services, while higher-level layer provide graphics and interface related service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*hzP_5v1w-vwe5pB-AwLGmA.png" /><figcaption>iOS Operating System sLayer</figcaption></figure><p><strong>8- What is the difference between Swift and Objective-C ?</strong></p><p>Ans - Both Swift and Objective-C languages are use for iOS App Development. Objective-C is primary language for building iOS App, while Swift is newer from Objective-C.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8MVXRjdUl9iRW5EQLF2pHw.jpeg" /><figcaption>Swift Vs Objective-C</figcaption></figure><p><strong>9- What is the difference between OOPS and POP programming ?</strong></p><p>Ans - The <strong>OOPS</strong> - Object Oriented Programming System, focuses on build code using Class , Object and Inheritance while <strong>POP-</strong>Protocol Oriented Programming emphasises using protocols and extensions.</p><p><strong>10- What is UIResponder Chain in iOS ?</strong></p><p>Ans - The UIResponder chain in iOS links the UIResponder objects that handle events in the App. The chain is a dynamic configuration of responder objects, which are instances of the UIResponder class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XIdBTQ9YCyVjg1cFoxmESQ.png" /><figcaption>UI Responder Chain</figcaption></figure><p><strong>Conclusion</strong>:</p><p><em>In this part we did cover some other basic questions of iOS swift. We will cover some other questions in next part of this series.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0a9f0061fe0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview Question in Swift Part - 1]]></title>
            <link>https://medium.com/@kavita4310ios/interview-question-in-swift-part-1-061e6d8bb133?source=rss-be027ca4ec13------2</link>
            <guid isPermaLink="false">https://medium.com/p/061e6d8bb133</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[swift-programming]]></category>
            <dc:creator><![CDATA[Kavita Chauhan]]></dc:creator>
            <pubDate>Thu, 30 May 2024 21:58:05 GMT</pubDate>
            <atom:updated>2024-05-30T22:00:24.565Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>In this part we will learn some basic and common questions, which is generally asked by Interviewers during Interview. So let’s start.</blockquote><p><strong>1. What are Closures and their Types ?</strong></p><p>Ans - closure’s are self contain block of function. We can assign variable, and pass as a argument inside function. Closure’s are reference type. Closure’s are divided in four types. 1- <strong><em>Trailing</em></strong> <strong>Closure, 2 - Auto Closure , 3 -Non-escaping Closure and 4 - Escaping Closure. </strong>By default closure is non -escaping type.</p><p><strong>2. Give me example where, In actual need to implement closure’s ?</strong></p><p>Ans - First, when we need to escape (execute later) some line of execution after returning function or getting response from api we can execute block of code through escaping closure’s . Second, If we need to implement execute particular block of code if value is true then we will use @ A<strong>utoclosure.</strong></p><p><strong>3. What are @ Autoclosure?</strong></p><p>Ans - Auto closure wrap the closure expression inside function arguments and we can’t pass argument inside closure block’s when we will use @ <strong>autoclosure</strong> .</p><p><strong>4. What is class and struct ?</strong></p><p>Ans - Both are building block’s of flexible construct, both can hold property and method’s. both have initialiser’s to create instance with initial value.</p><p><strong>5. Difference between class and struct ?</strong></p><p>Ans - Class are reference type. It uses heap allocation in memory. it have no default initialiser’s. it’s support inheritance while struct doesn’t support inheritance. it uses stack allocation in memory that’s why struct executed is bit fast compare to class. It doesn’t support inheritance. It have default initialiser’s</p><p><strong>6. What is Allocation. Difference between Heap and Stack allocation ?</strong></p><p>Ans - Allocation is a process of reserving space in memory by data. In stack allocation memory automatically free after executing function while heap allocation can hold reference of data for long time.</p><p><strong>7. What are Optional’s. Why we need to create Optional’s ?</strong></p><p>Ans - It is a way to create optional of any data types using ? expression, It can hold value or might be nil value at initialisation time. If the initial value is nil or will nil in future then we need to create optional.</p><p><strong>8. How many way to unwrap Optional’s ?</strong></p><p>Ans - We can unwrap optional’s using four ways. <strong>1</strong> <strong>Through Explicit unwrapping using ! , 2 Optional binding , 3 Optional chaining </strong>and<strong> Nil coalescing operator. </strong>Explicit unwrapping can cause crash if value will nil, So we should avoid explicit unwrapping</p><p><strong>9. What is Optional binding and Optional chaining ?</strong></p><p>Ans - Both are safe way to unwrapping optionals. Through optional binding we can check nil value before use it through guard let and if let statement while through optional chaining we can unwrap value using ? expression, their initial value might be nil or can hold value.</p><p><strong>10. What are Protocols. Why we need to create Protocols ?</strong></p><p>Ans - Protocols are blue print of method and properties. It can inherit by enum, class and structure.It support multiple inheritance. Through Protocol we can create methods optional using extension.</p><p><strong>11. What are Delegate and Protocol Delegate ?</strong></p><p>Ans - Delegates are reference to the class which is going to confirm that protocol while protocol delegate is a way to communicate or share data between classes.</p><p><strong>12. What are Protocol Delegate ?</strong></p><p>Ans - Protocol Delegate is a way to communicate or share data between classes. It uses for back calls.</p><p><strong>Conclusion</strong></p><p>Today did we learn some basic question of swift which is generally ask in interview. We will learn more question in next part.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=061e6d8bb133" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>