300+ [UPDATED] Swift Programming Interview Questions

  1. 1. What Do You Mean By The Term “defer”?

    The term “defer” is a keyword that provides a block of code that executes when the execution is leaving the current scope.

  2. 2. What Are The Control Transfer Statements In Swift?

    The control transfer statements in swift are:

    • Continue
    • Break
    • Fallthrough
    • Return
  3. Core Java Interview Questions

  4. 3. How Can You Define A Base Class In Swift?

    The classes are not inherited directly from the base class in the Swift programming language.The classes defined by the developer without specifying the superclass becomes the base class automatically.

  5. 4. Explain The Adapter And Memento Pattern?

    Adapter
    – It lets the classes with incompatible interfaces to work together and it wraps itself around the object to expose a standard interface to interact with that object.

    Memento –
    This pattern in iOS is used as a part of state restoration.

    That is this externalized state can be restored without violating any encapsulation.This pattern is especially used for the archiving in Apple.

  6. Core Java Tutorial

  7. 5. Explain Some Common Execution States In Ios?

    The states of the common execution can be as follows:

    Not running –
    This state means that there is no code that is being executed and the application is completely switched off.

    Inactive –
    This state means that the application is running in the background and is not receiving any events.

    Active –
    This state means that the applications are running in the background and is receiving the events.

    Background –
    This state means that the application is executing the code in the background.

    Suspended –
    This state means that the application is in the background and is not executing.

  8. UNIX/XENIX

  9. 6. What Is Dictionary In Swift?

    It enables you to store the key-value pairs and access the value by providing the key.It is similar to that of the hash tables in other programming languages.

  10. 7. Can You Explain Regular Expression And Responder Chain?

    Regular Expression –
    These are the special string patterns that describe how a search is performed through a string.

    Responder Chain –
    It is a hierarchy of objects that obtain the opportunity to respond to the events.

  11. Global Money Markets Tutorial
    Basic Programming

  12. 8. Explain Functions?

    It lets you group a series all together to perform a specific task.A function once created can be over and over in the code, and in case you find a repeating statement in the code, then the function can be the answer to avoid the repetition.

  13. 9. Explain Why A Compile Time Error Occurs. How Can You Fix It?

    Structures are value types. By default, the properties of a value type cannot be modified from within its instance methods.

    However, you can optionally allow such modification to occur by declaring the instance methods as ‘mutating’;

    EX:

    struct IntStack {

    var items = [Int]()

    mutating func add(x: Int) {

    items.append(x) // All good!

    }

    }

  14. Global Money Markets

  15. 10. Distinguish Between @synthesize And @dynamic In Objective –c?

    @synthesize –
    It generates the getter and setter methods for the property.

    @dynamic –
    It notifies the compiler that the getter and setter are implemented at some other place.

  16. IOS Tutorial

  17. 11. Can You Explain Completion Handler?

    • Typecasting Patterns
      – This pattern allows you to match or cast the types.
    • Wildcard Patterns
      – This pattern matches as well as ignores any kind and type of value.
    • Optional Patterns
      – This pattern is used to match the optional values.
  18. IOS

  19. 12. What Do You Do When You Realize That Your App Is Prone To Crashing?

    • Firstly, determine the iOS version or model of the device.
    • Collect enough information to reproduce the issue.
    • If possible, acquire device logs.
    • Acquire tooling or create a unit test and begin debugging once you get the idea of the nature of the issue.
  20. Core Java Interview Questions

  21. 13. How Can You Make A Property Optional In Swift?

    Declaring a question mark “?” in the code can make a property optional.

    If a property doesn’t hold a value, then this symbol “?” helps in avoiding the runtime errors.

  22. Javascript Advanced Tutorial

  23. 14. How Multiple Line Comment Can Be Written In Swift?

    The Nested multiline comments enable you to comment out large blocks of code quickly and easily.

    Use an opening (/*: ) and closing ( */) comment and it looks like –

    /*:

         The above forward slash (/) and an asterisk (*) then a colon (:) is opening comment – (/*:)

         …

         The below an asterisk (*) and forward slash is closing comment – (*))

    */

  24. 15. What Is A Deinitializer In Swift?

    If you want to perform an additional clean-up of your classes, it is possible to define a block called deinit.

    Syntax –

    deinit {

      //Your cleanup statement here.

    }

  25. Javascript Advanced

  26. 16. What Is The Significance Of “?” In Swift?

    The question mark (?) is used during the declaration of a property. If the property does not hold a value, the question mark (?) helps to avoiding application errors.

    Example looks like –

    class Employee {

      var certificate : [Certificates]?

     }

    let employee = Employee();

    Example 2 –

    let middleName : String? = nil

    let lastName : String = “Singh”

    let name : String = middleName ?? lastName

  27. Software Development Lifecycle (SDLC) Tutorial

  28. 17. What Is The Difference Between Swift And Objective-c Language?

    Swift Programming-

    • In a swift programming, the variables and constants are declared before use.
    • In a swift programming, “var” keyword used for variable and “let” keyword for constant.
    • In a swift programming, no need to end code with semi-colon
    • In a swift programming, does not require creating a separate interface like Objective-C.
    • In a swift programming, we can define methods in class, structure or enumeration.

    Objective-C Programming-

    • In objective-C programming, we need to end code with semi-colon
    • In objective-C programming, we can declare constant as int and variable as NSString.
  29. Software Development Lifecycle (SDLC)

  30. 18. What Are The Advantages Of Swift?

    • Swift is safe
    • Swift is fast
    • Swift is open source
    • Swift is approachable
    • Swift is easy to learn
  31. UNIX/XENIX

  32. 19. Is Swift Object Oriented Programming?

    Yes! Swift is an Object-Oriented Programming language.

  33. Objective C Tutorial

  34. 20. What Is Initialization ?

    Initialization is the process of preparing an instance of a class, structure, or enumeration for use. This process involves setting an initial value for each stored property on that instance and performing any other setup or initialization that is required before the new instance is ready for use.

    You implement this initialization process by defining initializers, which are like special methods that can be called to create a new instance of a particular type. Unlike Objective-C initializers, Swift initializers do not return a value. Their primary role is to ensure that new instances of a type are correctly initialized before they are used for the first time.

    Initializers

    Initializers are called to create a new instance of a particular type. In its simplest form, an initializer is like an instance method with no parameters, written using the init keyword:

    init() {

    // perform some initialization here

    }

  35. Objective C

  36. 21. What’s New Features In Swift 4.0?

    • Faster, easier to use Strings that retain Unicode correctness
    • Smart key paths for type-safe, efficient, extensible key value coding for Swift types
    • Added some enhancements to creating dictionary and Set types
    • Extends to supports of serialization to Struct
    • Tuples and multiple return values
    • Structs that support methods, extensions, and protocols
    • Native error handling using try/catch/throw
  37. 22. How To Connect Ui In Swift Language?

    Same as like c-objective. There is no change in binding process only core level has been changed. You can choose button/label on xib file and binding as is it.

  38. JSON (JavaScript Object Notation) Tutorial

  39. 23. What Is Best Way To Add A Table View?

    Open storyboard file in Xcode and lets drag in a “Table View” object from the Object Library (don’t use a table view controller.) Position this full screen in your app window and make sure it lines up with the edges. Then resize the height by dragging down the top edge and giving a little bit of space (this gives room for the status bar at the top of the phone.) If you run the app at this point, you should see an empty table view in the simulator.

  40. JSON (JavaScript Object Notation)

  41. 24. How To Define Ksomeconstant As An Integer?

    In this case kSomeConstant is implicitly defined as an integer.

    If you want to be more specific you can specify which type it is like so:

    let kSomeConstant: Int = 40

  42. Basic Programming

  43. 25. How To Define Variables In Swift Language?

    Constants and variables must be declared before they are used. You declare constants with the let keyword and variables with the var keyword.

    let maximumNumberOfLoginAttempts = 10

    var currentLoginAttempt = 0

  44. Unix/Linux Tutorial

  45. 26. What Is Swift Programming Language?

    Swift is an innovative new programming language for Cocoa and Cocoa Touch. Writing code is interactive and fun, the syntax is concise yet expressive, and apps run lightning-fast. Swift is ready for your next iOS and OS X project — or for addition into your current app — because Swift code works side-by-side with Objective-C.

  46. Mobile Developer