Curated iOS Interview Questions Series — Part 2

Rahul Goel
3 min readMar 5, 2021

--

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

Do check out Part-1 before proceeding further.

Q26. Higher order functions in swift?

Higher order functions are functions that takes another function/closure as argument and returns it

1. map
2. filter
3. flatMap
4. compactMap
5. reduce

Q27. Create your own Filter function in swift?

“Custom Filter Function”

Q28. Swift object life cycle?

“Swift object life cycle”

Q29. weak vs unowned in swift?

Weak references are always optional and automatically becomes nil when referenced object goes away.

Unowned object are never optional types, If you try to access unowned property that refers to de-initialized object, it will lead to runtime error similar to force unwrap nil optional type.

Q30. Example of swift object getting deallocated after end of scope.

Q31. What would be the output in Swift Playground?

Output: Empty String, instance of anotherObject would be immediately deallocated because it is marked as weak.

Q32. What would be the output in Swift Playground?

Q32
“Output”

Q33. What would be the output in Swift Playground?

“Q33"

Output: 3 1 2 as main queue is sequential

Q34. What would be the output in Swift Playground?

“Q34"

Output: a b c r w s m then runtime error before executing print(“p”)
Do checkout next Part-3 in series.

Follow me Rahul Goel for further updates.

--

--

Rahul Goel
Rahul Goel

Written by Rahul Goel

Engineering Manager - SonyLiv iOS | 11+ Year | @Sharechat, Groupon, Paytm, Myntra https://www.linkedin.com/in/therahulgoel/

Responses (1)