Interview Questions on iOS App Development

iOS/Iphone Tutorial

We have mentioned some Interview Questions on iOS App Development with Swift in this Article.

What is the difference between let and var in swift?

let and var are kind of variables in swift, but both have different usages.

If you want to define a variable of which you are sure that that value is not going to change throughout the execution of the program; then you can define the variable as let.

var keyword while defining a variable is used in the case when you are sure that, the value of this particular variable is going to get modified in the future execution of the program.

let a: Int = 11
// a is a variable with value as 1, but value cannot be changed, it has a fixed value assigned at the time of compilation.
var b:Int = 20
// b is also a variable whose value is 20, but value can be changed at runtime.
a = 111 // Compile time error
b = 22 // Changes the value from 22 to 20
print(b) // Prints the value of b

 How are structures different from class?

Structures are value types but classes are the instance or reference types.

For example, if we copy an instance of a struct to another instance the values are just copied any changes in any of the references will be restricted to the particular instance only.

But in classes, if we assign an instance of a class to another one; then changes in one will affect the values of other instance as well.

How is static different from let in swift?

A static variable is shared through all instances of a class.

What is optional chaining?

It is a process by which we can query property and methods for the value such that; if the optional might currently be nil, or it possesses a valid value.

To specify optional chaining we place a ? For which we need to specify that it’s going to be an optional value.

It is similar to adding a ! In front of the value which we defined as forced unwrapping, but at the time of execution if the value is nil in case of ? It fails gracefully by giving a value as nil but in the case of ! It will generate a runtime Exception.

What are extensions in swift?

With the help of extensions in swift we can add new functionality to an existing class.

Usage :

extension someType {
  // Add new functionality here.
}

How would you define an array and dictionary in swift?

Code for defining an Array and Dictionary

var arrIntVal : [Int] = [0,1,2,3] // Array with 4 values of type integer
var dictVal: [String : Int ] = [ “age”:25, “height”:6]

How would you define a function in swift?

Functions can be defined in following ways

 

Syntax: Function with parameters.
func functionName(functionLabel parameter1:type) -> returnType {
// Statements
return value
}
Function without parameters and returnType
func functionName() -> returnType {
// Statements
return value
}
Function without parameters and no return type
func functionName() {
// Statements
print(“Easy solutions web”)
}

func is a keyword which tells that a function is being written.

functionName specifies name of the function.

functionLabel the label will be visible at the time of function calling.

parameter1 is the name of the parameter; its scope is well defined within the {}.

type is the kind of value which parameter1 would persist.

returnType what kind of value the function will return.

Read our new set of interview questions on iOS app development here