Intern iOS Developer Interview Questions and Answers

Tram Ho

Each iOS developer has its own unique knowledge and experience through projects. However, how much do you really understand Swift? In this article, we will help you learn more about sample Swift interview questions. You can use these questions to interview candidates. Or you can check it for yourself, and don’t worry if you can’t answer it, as each question has its own resolution.

Usually people are divided into 3 levels:

  • Beginer: Comfortable for Swift novices. You’ve read 1 or 2 books, and used Swift in your own app.
  • Intermediate: For those who have worked with Swift on real projects and learn about them in depth.
  • Advanced: Those who have a lot of development experience – truly understand and use advanced techniques

Each level, you will have 2 types of questions:

  • Written Questions: Email coding tests, related to coding.
  • Speaking Question: In person or by phone interview

Basic question:

Question 1:

Read the code below

What is the value of tutorial.difficulty and tutorial2.difficulty ? If Tutorial is class type, what’s the difference? Why and why not? Answer: The answer: tutorial.difficulty is 1 and tutorial2.difficulty is 2. Struct in Swift is value type. Because you copy the value of the variable instead of the reference. The code makes a copy of tutorial 1 and assigns it to tutorial 2.

Changing tutorial2 has no effect on tutorial1 If Tutorial is class type, both tutorial variables will have value 2. Because Class in Swift is reference type. When you change the variable tutorial 1, it will refer to tutorial 2 and change it.

Question 2:

You declare view1 with var, and then declare view2 with let, what’s the difference with the last line?

Answer: The last command line will be run, view1 is a variable type, and you can be an object of UIView. With let, you can assign the value once to it, so the code below will not be executed

However, UIView is the reference class type, so you can change the properties of view2 – that means the last line of code will be executed:

Question 3

The code below will sort the name according to the alphabe table. The closure section is simple that you need

Answer: The reference value will be automatically calculated by the system, and return the corresponding value type, you can write shorter like:

You can substitute $ i for the name of paramter:

In the single closure type, you can omit the return keyword. The value of the statement becomes the closure’s data:

Finally, when Swift knows that elements from arrays are Equatable, you can write them simply:

Question 4

Here is a global function that counts the number of unique values ​​in an array:

It uses sorted, uses the variable type T, which matches Comparable. You can call it as follows:

It is possible to rewrite the function as an extension for Array, so you could write it like this:

Answer: You could rewrite countUniques (_:) as an extension of Array:

The function can now be used with any generic Element type satisfying Comparable.

Question 5

This is a function to split two mirrored options. There are three prerequisites for verifying before doing the actual split:

  • Dividends must contain a nonzero value.
  • The divisor must contain a nonzero value.
  • Divisor cannot be zero.

Improve the above function with using the guard command and not using fored unwarpping.

Answer: The guard statement introduced in Swift 2.0 provides an exit when a condition is not met. It is useful for testing prerequisites as it allows you to express them explicitly – no nested if statements. Here is an example:

You can also use statement for optional binding, which will access data after passing the guard statement:

So you can rewrite funtion divide like this:

Notice the absence of implicit unpacked operators on the last line because you unpacked both the divisor and divisor and stored them in non-optional invariants. Note that the results of the unwrapped options in a guard statement are available to the rest of the code block in which the statement appears. You can simplify this even further by grouping the guard statements:

Share the news now

Source : Viblo