What to expect from an iOS Code Challenge?

Fernando Moya de Rivas
6 min readSep 25, 2019

--

Recently, I’ve had the chance to participate in several code challenges as I’ve been job-hunting myself. In this post, I intend to tell you what two kinds are the most popular you’ll find out there and give you some tips to successfully pass them and make a good impression. You’ll find some of the assignments I’ve worked on in my GitHub profile.

So what is a code challenge?

A code challenge is basically an assignment that most companies send you to prove yourself as a software developer. It’s an opportunity to stand out and show them what you are capable of. They’re going to pay attention to the way you code, that is, how you structure it, the patterns you use and what architecture you pick.

This stage of the process is highly important as companies no longer trust certifications or experience you may have in your resumes and are more keen on seeing how you cope with the test they’ve prepared for candidates applying for the open position.

Types of code challenges

As I mentioned, I’ve been struggling lately in several processes and have completed many assignments. Not one of the companies I was applying to skipped this step.

What did I encounter? There are two main assignments you’ll run into:

  • Algorithm tasks
  • Short functional iOS project

In the following sections, I’ll explain what each of these assignments consist of and give a piece of advice about how to deal with them.

Algorithm tasks

The assignment will be something generic that they most probably send to almost anybody who’s applying for a software development position, no matter if it’s front or backend. It consists of one or several tasks. The goal here is to see how you model a problem and successfully solve it. If you have never taken any of these tests, there’s a good way to practice using some available free platforms. I’m listing some of them below:

These platforms work all the same. Basically, the screen is divided into three sections. On the left, you’re presented with the instructions of the task whereas on the right you can find the console editor, which is subdivided in two: the solution and some test cases. Running your code and passing the tests doesn’t mean your solution is correct. When you submit the task, the server will run far more extensive tests where performance is extremely important.

This type of assignment looks very similar to this. They just add some extra difficulty: a countdown timer, which means your time to solve the task is limited. There’s a subtle difference, nonetheless, between the tasks I’ve been asked to solve and that you can also notice when messing around these platforms. Whereas Codewars or Hackerrun won’t let you pass the tests if some of the outputs are incorrect or the code doesn’t perform well enough, Codility will let you submit the code and will analyze it right after in order to rate it. This rating is based on two factors: correctness and performance, that is, the ratio of tests passed and the ratio of tests that didn’t timeout. They also record the lines of code and the time you spent on the task. I particularly find this last kind more difficult since it’s easy to miss something when coding a solution, whereas with Codewars or Hackerrun the task won’t be submitted and you’ll have time to fix it.

The sort of algorithm varies a lot. They aren’t very complex as they usually time out after 30 minutes. Nonetheless, make sure you know which kind it is and beware of the time.

One example could be the implementation of the algorithm of a vending machine: “Implement a function that takes as arguments two float numbers. The first one is the price of an item in a vending machine. The second one is the amount introduced to pay for the item. The function output should be an array of integers that represents the number of coins of 1cc, 5cc, 10cc, 20cc, 50cc and 1€ that should be returned. The number of coins returned should be the lowest possible”.

Short functional iOS project

Here, they’ll send instructions to build an App that most likely will sort some items retrieved from the network. When clicking any of the items displayed, the App should navigate to a detail view. The information to display depends on the instructions and the API provided and sometimes they ask you to implement some kind of logic in this scene.

Although at first sight, this isn’t difficult at all and it shouldn’t take you more than a couple of hours, what they’re expecting is to see how you work. You wouldn’t request data or implement any logic in a UViewController , would you? That means this challenge is your way to show the reviewers everything you know about software, frameworks you’re familiar with and your code style. SOLID principles, legibility of your code, Clean Architecture … all this comes to play at this point. Check out my GitHub profile to find some examples.

What I usually do? I always separate my code in layers, according to the Clean Architecture guides, by differentiating between:

  • User interface: anything that has to do with UIKit.
  • Business logic: any use cases that they might ask, like any complex calculation, sorting, …
  • Domain: plain objects that will model your App content.
  • Repository: HTTP requests and any other kind of data storage they might ask as well as any kind of mapping to the domain entity.

This separation has worked fine for me and I’ve never needed to add any additional layers. Each layer is a Cocoa Framework, that is, a new target of the App. Therefore, they could be easily extracted and uploaded to a private repository in case they were to be reused by another App.

Regarding architecture, I always use MVVM. This architecture is very popular now and you can find lots of documentation about how it works. Besides, both Google and Apple are developing new frameworks to support it so that makes it even easier. MVVM is based on the observer pattern and works great with reactive programming. By this, I don’t mean you should add RxSwift, ReactiveCocoa or Combine as dependencies. It’s about the concept. The naming of the function/block is what will give an impression of reactiveness. Reactive programming is a very trending topic that some companies ask for or are interested in. I honestly recommend using this kind of rule for a short project like this.

Another thing that reviewers have asked me about is DI and Navigation. I usually inject dependencies by using containers which would potentially give flexibility if any dependency is to be changed. Regarding Navigation, I tend to free the ViewController from this responsibility and create a special component for the task. I’ve used both Navigator and Coordinator pattern for this purpose and, to be honest, the latter draws more attention than the former.

Although not always requested, they’ll usually demand a public URL to a repository, such as Github. If so, I would consider following a GitFlow approach. It won’t take you much time to create branches and merge them. A README file explaining decisions made throughout the development will surely help too.

Finally, if after all this work you’re still willing to spare some more time, there’s something else you could add: animations. Add a beautiful reveal transition after an initial Splash ViewController. Polish up the UI, even if they say you don’t take too much time on it. It looks good and at the end of the day, you’re trying to impress them.

Conclusions

Take very seriously these challenges and put aside some time for them. They’re a chance to demonstrate your skills and to prove you’re more valid than other candidates. Don’t be afraid to experiment with new concepts and make sure your code is legible and understandable by other developers. Watch the time and try to practice first before attempting any of them.

--

--

Fernando Moya de Rivas

Enthusiast of Mobile development, interested in Art and Design.