Interview Questions on iOS App Development

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

Generate a CSR file for iOS Applications

The purpose of this article is successfully creating a CSR file. CSR is an abbreviation for Certificate Signing Request.

Firstly to get a valid certificate from the developer console, you must generate and CSR file on the mac machine using the Keychain access app; with the help of this file actually Apple verifies you and your system, it’s just like we are asking for a Permission for doing stuff; and in return Apple gives us a certificate.

Steps for creating a CSR file.

  • Open Keychain Access application on Mac.
  • To open keychain Access application, press (Command + spacebar). Spot light search opens; spotlight search is an default search kind of application provided by apple so that you can find any file located at any particular location on your mac device
iOS Tutorials: Open keychain Access Application on Mac
Open keychain Access Application on Mac

 

  • Once the keychain Access application starts, click on Keychain Access menu on the top bar, beside the Apple Menu.
iOS Tutorials: Click on Certificate Assistant.
Click on Certificate Assistant.

 

  • Click on “Request a Certificate from a Certificate Authority”.
iOS Tutorials: Click on "Request a certificate from a certificate authority".
Click on “Request a certificate from a certificate authority”.

 

  • A popup window will appear asking for some general information like, User Email Address, Common Name, Email Address, CA Email Address and where do you want the CSR file.
iOS Tutorials: Click on continue to proceed further.
Click on continue to proceed further.

 

  • Click on continue, once done with filling all the entries.
    • Make sure the saved to disk check box is checked.
  • A popup window will appear asking for the name of the CSR file.
  • Please enter the desired name and give a proper location where you want to save this file.
iOS Tutorials: Give proper name to the generated CSR file with destination.
Give proper name to the generated CSR file with destination.

 

  • This process finishes the creation of a CSR file, now click on “Show in finder” button to get the CSR file.
iOS Tutorials: Mac: CSR created successfully!!
CSR created successfully!!

Note: As we have given the location as Desktop, the CSR file is now saved on the Desktop.