What is use of defer keyword in swift?

defer is a guard statement that provides as block of code that executes when the execution is about to leaving its current scope.

What are the control transfer keywords in Swift?

The control transfer keywords in swift are Continue,Break,Fallthrough and Return.

What are the life cycle of iOS App?

Not running: In this state code is not being executed and the application is off.

Inactive: In this state the application is running in the background and not receiving events.

Active: In this state the application is running in the foreground and receiving the events.

Background: The application is executing the code in the background.

Suspended: The application is in the background and not executing code.

What is dictionary in Swift?

Dictionary allows to store key-value pairs and access the value by key.

What is responder chain?

The responder chain is a sequence of linked responder objects.If the first responder unable to handle an event, it forwards the event to the next responder in the responder chain. A responder object is an object that can respond and handle the events.

When should you use a structure, and when should you use a class?

The difference between class and structure in swift are as follows-

  • Class support inheritance, structure don't support it.
  • Class are reference type, structure are value type .

Note- If you need inheritance or reference semantics use class other wise use structure because at runtime, structure are more fast than class because method invocations are statically bound in structure, whereas method invocation for class is dynamically resolved at runtime.

How can you declare a property optional in Swift?

By using question mark (?) you can make property optional. If property don't have value it will not throw error with optional property.

What is deinitializer in Swift?

deinit is used to deallocate additional memory before deallocating the object, you can define a block with deinit keyword.

Syntax -

deinit {

//Your deallocate statement here.


What is initialization ?

Initialization is a process of assigning the value to property of structure or class or a variable.

In swift initializer is like an instance method with no parameters, written using the init keyword:

init() {

//initialization code


How to define variables in Swift Programming?

You can declare the constants using let keyword and variables with the var keyword. Variables and constants must be declared before use.


var variableName : DataType

var year:Int
year = 2

var year:Int = 2 //variable declaration in single line:

var year = 2 // use of type inference

What are differences between Foundation and CoreFoundation?

Core Foundation is the C-level API, which provides CFString, CFDictionary etc . CoreFoundation is the common base of Foundation and Carbon.

Foundation is written in Objective-C, which has lot of more classes like NSString, NSDictionary etc.

What is unwind segue?

An unwind segue moves backward through one or more segues to return the user to a root or previous view controller.

What is CocoaTouch ?

CocoaTouch is a library used to build executable applications on iOS. CocoaTouch is an abstract layer on the iOS.

What is the difference between private and fileprivate in Swift 4?

It is applicable in swift 4.0 and its later versions-
Private: Private access modifier is only accessible in class and its extension ,if extension is in the same .swift file.

File Private: File-private access modifier is accessible only in class and its extension & subClass if extension and subClass are in the same .swift file.

What is use of inout parameters?

Function parameters are constants by default if try to change the value of function parameter in body of function it will through compile time error.If there are any such requirement to change function parameter, we will use inout keyword to define the function parameter. see the example below-

func add(x:Int,y:Int)->Int{

x = 10 // give error :Cannot assign to value: 'x' is a 'let' constant



func add(x:inout Int,y:Int)->Int{

x = 10 // no error will generate



What is the open keyword in Swift?

difference between open access modifier and public are as follows-

  1. Classes with public access can be subclassed only within the module where they’re defined.
  2. Class members with public access can be overridden by subclasses only within the module where they’re defined.
  3. Open classes can be subclassed within the module where they are defined or can be subclassed in the module where they are imported.
  4. Open classes can be overridden within the module where they are defined or can be overridden in the module where they are imported.

What is difference between struct and class in Swift?

Struct is value type and Class is reference type.

What is subscript in swift?

Subscripts are used to get value from a collection, sequence and a list in Classes, Structures and Enumerations.

What is typealias in swift?

typealias  keyword is used to define new data type from existing data type. The purpose of typealias keyword to make your code readable and clear to understand.

What is use of fallthrough keyword in swift?

A fallthrough keyword is used in switch case to execute the case which is next to matched case.

for example-

var sum = 0
var i = 3
switch i {
case 1:
sum += i
case 2:
sum += i
case 3:
sum += i
fallthrough //allows for the next case to be executed
case i % 3:
sum += i

Back to Top