iOS Interview Questions — Part1

Some of the areas to refresh before an iOS Technical Interview.

  • Simplest way to remove duplicates from Array ?
  • Database — difference between relational and non relational db
  • Why use Core Data over SQLite3
  • How to migrate users in Core Data
  • Classes vs Structs
  • Escaping vs Non Escaping Closures
  • MVVM vs VIPER
  • Complexity — N(0) square of performing enumeration over for loop (From Qn. 1)
  • Inheritance vs Categories
  • Singleton? What happens when multiple objects access same Singleton?
  • Fast enumeration?
  • Function overloading / method overloading
  • Table view vs collection view — when to use which
  • KVO and KVC

Answers:

  1. Removing duplicates ?
  • Duplicate Int in Array , Dictionary or Set in SWIFT. Reading up on Sets and Arrays I find that a Set cannot, or is not able to store duplicate values ( Ints, Strings, etc ).
  • let unique = Array(Set(originals))

Ref: https://stackoverflow.com/questions/25738817/removing-duplicate-elements-from-an-array-in-swift

2 . DifferenceCoreData & SQLite

  • Coredata is a framework to manage database, CoreData is not a database. Core Data can use SQLite as its persistent store
  • SQLite — is a relational database

Ref: https://medium.com/@rathish/core-data-43d6d74354c3

3 . How to migrate users in CoreData ?

Migrations happen in three steps:

  • First, Core Data copies over all the objects from one data store to the next.
  • Next, Core Data connects and relates all the objects according to the relationship mapping.
  • Finally, enforce any data validations in the destination model. Core Data disables destination model validations during the data copy.

Ref :https://www.raywenderlich.com/7585-lightweight-migrations-in-core-data-tutorial

4 . Class vs Structs ?

  • Structs — Structs are value types
  • Classes — Classes are reference type

Ref: https://blog.usejournal.com/swift-basics-struct-vs-class-31b44ade28ae

5 . Escaping vs Non Escaping Closures ?

  • @nonescaping When passing a closure as the function argument, the closure gets execute with the function’s body and returns the compiler back. As the execution ends, the passed closure goes out of scope and have no more existence in memory.
  • @escaping — When passing a closure as the function argument, the closure is being preserve to be execute later and function’s body gets executed, returns the compiler back. As the execution ends, the scope of the passed closure exist and have existence in memory, till the closure gets executed.

Ref: https://medium.com/@bestiosdevelope/what-do-mean-escaping-and-nonescaping-closures-in-swift-d404d721f39d

6 . MVVM vs VIPER ?

MVVM has only a view component in UI layer, VIPER separates UI responsibilities into 3 components, which are View, Presenter and Router. It’s also obvious that business layer looks pretty much the same.

Ref: https://medium.com/developermind/blurring-the-lines-between-mvvm-and-viper-dcb3dc9815ac

7 . Complexity of for loop?

  • O(nc): Time complexity of nested loops is equal to the number of times the innermost statement is executed. For example the following sample loops have O(n2) time complexity

Ref: https://www.geeksforgeeks.org/analysis-of-algorithms-set-4-analysis-of-loops/

iOS Enthusiast 📱 • LinkedIn: https://www.linkedin.com/in/rathishkannan/ • GitHub: https://github.com/ratzr15 • StackOverflow: https://stackoverflow.com