Latest Post

SwiftUI interview questions and answer How to display SwiftUI sheet Half screen SwiftUI CollectionView using Vgrid

swift interview questions for iOS developer: Part 1

swift interview questions and answers for Experience Developer and fresher

1.What is Struct in Swift?

Struct  is the value type object, it is the member-wise initialiser. it is called as value type because it passes the value to  the function,  when u use the struct whole thing is duplicated.it points the value of the  object. it shows he value of the object
Defining a Struct
Struct School {
    var clothes: String
    var shoes: String
}

2. What is Class in swift ?

Class is the reference type of object. it passes the reference data to the function . when class is used each object points to the same original  object if you change one they all will change. it show the reference of the real object
class School {
    var clothes: String
    var shoes: String
}

3. What is completion handler in swift ?

A completion handler is the function basically used to get the parameter .it notify the completion of process .it is used to return the value . it is basically used in network call session.
2 types of completion handler :
1. Asynchronous : task execution is done at same time
2. Synchronous: task execution is one after the another

4.What is difference between frame and bound ?

frame changes parent view layout .bound changes only child view layout

5. What is tuple?

Tuple is the used function to return multiple value it may be of different datatype. Tuple is the value type object
func split(name: String) -> (firstName: String, lastName: String) {
    let split = name.components(separatedBy: " ")
    return (split[0], split[1])
}

6. Whats is higher order function?

Higher order functions are simply functions that operate on other functions by either taking a function as an argument, or returning a function

7 .What is inheritance?

A Capacity of the class to derive property or characteristic from another class
here SomeSuperclass is the parent class and someSubClass is the child class
  1. class SomeSuperclass {
  2. // baseclass definition goes here
  3. }
  1. class SomeSubclass: SomeSuperclass {
  2. // subclass definition goes here
  3. }
 example :
  1. class Fruits {
  2. var weight = 0.0
  3. }
  1. class Mango: Fruits {
  2. }
  1. let mango = Mango()
  2. mango.weight = 215.0
 

 8. What is singleton class in swift ?

SingleTon class is the  object  which provide single point of access to the function of the class

example:

Class Common  {

static let shared = Common()

private init()

     func sum()-> Int {

        return 10 + 20

     }

}

accessing the singleton

let Sum = Common.shared.sum()

print (Sum)

output Sum = 30

 

 9. What are the feature only available in class compare to struct in swift?

 * Type Casting : We can check the type of the class in runtime.

    * Reference Counting : Allow more than 1 reference to the class instance

 * Inheritance : A class can inherit the property or characteristic of other class but in struct we cannot.

 * De initialisation : we can de-initialise the class resource at any instant.

 

10 . What is optional Chaining?

Optional Chaining is the Process of querying and calling the properties with an optional that may be nil

let object = {}

object?.data = 1

 

Please comment for more interview Question for iOS swift interview questions