iOS Interview Questions
iOS Interview Questions
Contextualize
How do you answer an interview question?
Contextualize
Reformulate the question and state the assumptions you will
make when answering.
Contextualize
Answer
How do you answer an interview question?
Answer
Give the explanation, the de nition or the best practice that
the interviewer expects to hear.
fi
How do you answer an interview question?
Contextualize
Answer
Recap
How do you answer an interview question?
Recap
Quickly sum up the key points of your answer, in one or two
sentences maximum.
And if you have more knowledge on the topic, it’s also the
moment to mention it!
How do you answer an interview question?
Contextualize
Answer
Recap
Now let’s answer some actual questions!
Question #01
What’s an Optional?
#01 – What’s an Optional?
Contextualize
One of the goals of Swift is to be a safe programing language.
Answer
Of course, in most situations we want to deal with the
Optional in a safe way.
Answer
Such closures are called “escaping closures” and must be
annotated with @escaping.
Answer
However, Swift provides us with tools to capture references in
a safe manner, using the closure’s capture list.
But not all closures have the potential to create such memory
leaks.
Recap
And that’s why Swift forces us to explicitly annotate such
closures with @escaping.
Answer
Properties are expected to have some speci c semantics:
Answer
If all these conditions are met, then it’s OK to encapsulate
that code inside a computed property.
However, if not all of them are met, then it’s better to use a
method, because the code doesn’t behave like we expect a
property to behave.
#03 – When would you use a computed
property vs a method?
Recap
Syntax sugar, like computed properties, can be really useful
to write shorter code.
It’s usually a bad idea to use sugar syntax when 100% of the
requirement are not meant, because it leads to confusion.
Question #04
Can you explain the purpose of
the keyword guard?
#04 – Can you explain the purpose of the
keyword guard?
Contextualize
When we implement a feature, we can usually split our code
into two parts:
• the “error paths”, which deal with all the potential technical
and business errors (no network, expired token, invalid
promo code, etc.)
#04 – Can you explain the purpose of the
keyword guard?
Answer
Ideally we would like the happy path to read like the main ow
of our code, and have the error paths branch out of it.
fl
#04 – Can you explain the purpose of the
keyword guard?
Answer
It’s when the keyword guard comes into play!
fl
Question #05
Can you give an example of a bad
practice in Swift?
#05 – Can you give an example of a bad
practice in Swift?
Contextualize
Bad practices are situations where what initially felt like a
good idea actually turns out to have harmful consequences.
Answer
When we’re dealing with symmetrical calls, the upside of
using defer de nitely makes it worth it.
Answer
A weak reference is meant to be used when the other
instance has a shorter lifetime.
Recap
However, unless you write computation intensive code that
requires every possible optimization, its unlikely that you will
notice any performance issue by using only weak references.
ff
Question #07
When would you use
@autoclosure?
#07 – When would you use
@autoclosure?
Contextualize
@autoclosure in an attribute that we can apply to a closure
argument.
Imagine that:
• the expression you pass is potentially expensive to
evaluate
• the function you pass it to might not always need to use it
fi
#07 – When would you use
@autoclosure?
Answer
In that situation, it could be useful to have a mechanism to
only evaluate the expression when we actually need to use it.
It’s not obvious at the call site that the expression we pass as
an argument will not be evaluated immediately, if at all.
Answer
Older projects might use CocoaPods or Carthage to deal with
dependencies. However more recent project will more like
use the Swift Package Manager instead.
#08 – What open-source tools do you
recommend using and why?
Recap
There are a lot of useful open-source tools out there that do a
great job at proving features that are not available in Xcode.
Because new APIs are (most of the time) not back ported to
older versions of iOS, this choice has strong technical
consequences.
#09 – How do you choose the minimum
version for an iOS app?
Answer
For instance, SwiftUI isn’t available before iOS 13. (And to be
honest, only becomes really usable with iOS 14)
The same way, Combine also isn’t available before iOS 13.
#09 – How do you choose the minimum
version for an iOS app?
Answer
Because you might not be able to use such important APIs,
the minimum version of iOS your app supports has major
consequences on your technical choices as a developer.
This way we would get to use all the modern APIs, and we
would save a ton of time testing our app on older iOS
versions.
#09 – How do you choose the minimum
version for an iOS app?
Answer
But doing so would make our app unusable by a potential
large part of iPhone users.
On the other hand, apps that deliver cutting edge tech can
assume that their users update their devices more regularly
and so can a ord to support less versions.
ff
#09 – How do you choose the minimum
version for an iOS app?
Recap
Deciding on the minimum version of iOS an app will support
is de nitely not an easy choice, and is often the result of a
compromise between business and engineering.
Answer
To solve this issue, we need to decouple the creation of a
dependency with its actual use.