Curated iOS Interview Questions Series— Part 1

Rahul Goel
5 min readFeb 13, 2021

Series aiming to cover as many Q&A’s as possible from iOS interview perspective.

Q1. What is type-safety in swift?

It means you need to be clear with type of value you want, If its String you can not pass Int by mistake, Swift performs type check at compilation and flags if there is any error.

Want to read this story later? Save it in Journal.

Q2 : UIButton class Hierarchy?

NSObject → UIResponder → UIView → UIControl → UIButton

Q3. Super class of UIViewController and UIWindow ?

UIResponder → UIViewController

UIView → UIWindow

Q4. List all access specifiers in swift?

open, public, internal, fileprivate, private

Q5. What is default access level of all entities in swift?

internal

Q6. Difference in open and public access specifiers in swift?

unlike public, open allows subclassing and overriding outside the module of the code.

Q7. What is module in Swift?

A module is a single unit of code distribution — a framework or application that is built and shipped as a single unit and that can be imported by another module with Swift’s importkeyword.

Each build target in XCode is treated as separate module in swift.

Q8. What is method swizzling in swift?

Process of changing the implementation of an existing selector at runtime, or we can change the functionality of a method at runtime.This is an Objective-C runtime feature.

Q9. How do you create Singleton class in Swift?

“Singleton class”

Q10. What is lazy loading in Swift?

“Lazy Loading in Swift”

Q11. Can we have lazy let or constants in Swift?

No, lazy properties can only be lazy var or variables not constants.

Q12. Do we need to mark static properties as lazy explicitly?

No, static properties are implicitly lazy loaded.

Q13. What are closures in Swift?

Closures are self-contained blocks of functionality that can be passed around and used in your code. Closures in Swift are similar to blocks in Objective-C.

“Closure in Swift”

Q14. Escaping vs Non-Escaping closures?

Escaping Closure : Storing the closure to a global variable, property, or any other bit of storage that lives on past the function call means the closure has also escaped. By the time the function ends, the closure could still be out there in the world somewhere, that we can use later on.

Non-Escaping Closure : When the function ends, the passed-in closure goes out of scope and there were no additional references made to the closure.

“Escaping vs Non-escaping closure”

Q15. What is default types for closure in swift?

Non-escaping

Q16. How to stop method overrides and subclassing in Swift?

by marking them final.

“final class”
“final method”

Q17. Extensions in swift?

Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for which you do not have access to the original source code (known as retroactive modeling).

“Swift Extensions”

Q18. Can we override existing functionality in extensions?

No, Extensions can add new functionality to a type, but they cannot override existing functionality.

Q19. mutating keyword in swift?

By default properties of value types cannot be modified within its instance methods . In order to modify the properties of a value type, you have to use the mutating keyword in the instance method.

“mutating Example 1”
“mutating Example 2”

Q20. Extension vs Subclass in swift?

  • Extensions can add new functionality to a type, but they cannot override existing functionality unlike subclass
  • Extensions can add new computed properties, but they cannot add stored properties, or add property observers to existing properties

Q21. class vs struct in swift?

classes are reference types, uses ARC, Inheritance possible and class type can be checked at run time.

struct are value value types, does not uses ARC, Inheritance not possible

Q22. Can enums have stored properties in swift?

No,

“Enums in Swift”

Q23. Difference between Self and self in Swift?

The Self type isn’t a specific type, but rather lets you refer to the current type without knowing that type’s name.

In a protocol declaration, the Self type refers to the eventual type that conforms to the protocol.

In a structure, class, or enumeration declaration, the Self type refers to the type introduced by the declaration.

“Self Example”

Self refers to the runtime type not compile time.

whereas self refers to specific current type or instance of the type.

“self Example”

Q24. Nil coalescing operator in swift?

“Nil coalescing operator”

Q25. Create your own Map function in Swift?

Here is next Part-2 of series.

Follow me Rahul Goel for further updates.

--

--

Rahul Goel

Computer Science Enthusiast | 11+ Year of Software Evolution | @Sharechat, Groupon, Paytm, Myntra https://www.linkedin.com/in/therahulgoel/