Logo for tanaschita.com

iOS Interview Questions and Answers for Senior Developers Part 2 - Networking

Check your knowledge on general computer networking concepts and networking in iOS

01 Oct 2019 · 5 min read

This post is part of a series

iOS Interview Questions and Answers For Senior Developers

I recently got into the position of leading the technical interviews when my client was hiring a new iOS developer. It's a challenging task to evaluate the skills and knowledge of another developer. In this post, I share the results of my most useful iOS and Swift questions and answers.

The purpose of the interview questions in this part is to get to know the developers general knowledge on networking concepts and to check their specific knowledge on networking in iOS.

Two dogs in front of a computer.
Hey buddy, let's find out how to do some networking.

So let's get started with the interview questions and answers.

1. What are the main components of a HTTP URL? What purpose do they have?

Every HTTP URL consists of the following components:

  • Scheme - The scheme identifies the protocol used to access a resource, e.g. http or https.
  • Host - The host name identifies the host that holds the resource.
  • Port - Host names can optionally be followed by a port number to specify what service is being requested.
  • Path - The path identifies a specific resource the client wants to access.
  • Query - The path can optionally by followed by a query to specify more details about the resource the client wants to access.

2. Give some examples of HTTP request methods you know. What purpose do they have?

HTTP defines a set of request methods to indicate the desired action to be performed for a given resource. Examples are:

  • GET - retrieve a resource
  • POST - create a resource
  • PUT - update a resource
  • DELETE - delete a resource

Other HTTP request methods are HEAD, OPTIONS, PATCH etc.

3. How would you create a HTTP request in iOS?

One way of creating a HTTP request in iOS is by using URLRequest with URLComponents.

var components = URLComponents()
components.scheme = "https"
components.host = "api.github.com"
components.path = "/search/repositories"
components.queryItems = [
URLQueryItem(name: "q", value: "swift"),
URLQueryItem(name: "sort", value: "stars")
let url = components.url

With URLComponents you can easily define the URL components and then create a URLRequest out of it.

4. How would you send and receive HTTP requests in iOS?

One possibility for sending and receiving HTTP requests is by using URLSession. With URLSessionConfiguration, you can configure caching behaviour, timeout values and HTTP headers.

A session works with tasks. After creating a session you can use URLSessionDataTask to send a request and to get the response:

let urlSession = URLSession(configuration: .default)
let task = urlSession.dataTask(with: url) { data, response, error in
// Handle response.

You can also use URLSessionDownloadTask to download and URLSessionUploadTask to upload files. You can suspend, resume and cancel tasks.

5. The server response contains a HTTP status code. Give some examples and explain their meaning.

The HTTP response status codes are separated into five categories:

  • 1xx Informational: Request was received, process is continuing.
  • 2xx Successful: Request was successfully received, understood and accepted.
  • 3xx Redirection: Further action needs to be taken to complete the request.
  • 4xx Client Error: Request contains bad syntax or cannot be fulfilled.
  • 5xx Server Error: Server failed to fulfill an apparently valid request.


  • 200 OK: Request was successful.
  • 201 Created: Request was successful, a new resource was created.
  • 400 Bad Request: Server did not understand the request.
  • 401 Unauthorized: Authentication has failed.

6. In iOS, a networking feature called App Transport Security (ATS) requires that all HTTP connections use HTTPS. Why?

HTTPS (Hypertext Transfer Protocol Secure) is an extension of HTTP. It is used for secure computer network communication. In HTTPS, the communication protocol is encrypted using TLS (Transport Layer Security).

The goal of HTTPS is to protect the privacy and integrity of the exchanged data against eaves-droppers and man-in-the-middle attacks. It is achieved through bidirectional encryption of communications between a client and a server.

So through ATS, Apple is trying to ensure privacy and data integrity for all apps. There is a way to circumvent these protections by setting NSAllowsArbitraryLoads to true in the app’s Information Property List file. But Apple will reject apps who use this flag without a specific reason.

7. RESTful APIs typically return the response data in JSON format. What value types are supported by a JSON schema?

JSON supports four basic value types and two complex data types.

The basic types are string, number, boolean and null.

The complex data types are object and array. An object is an unordered set of name/value pairs. An array is an ordered collection of values.

8. How would you convert a JSON response into native Swift types?

Swift’s Codable protocol makes it easy to convert JSON to native Swift structs and classes. The first step is to define a Swift type that has the same keys and value types as the JSON and conforms to Codable. For example:

struct Doggy: Codable {
let name: String
let age: Int

Then we can use JSONDecoder to convert:

let decoder = JSONDecoder()
do {
let doggies = try decoder.decode([Doggy].self, from: jsonData)
} catch {

9. What is the basic idea behind the OAuth protocol?

OAuth lets users grant third-party services access to their web resources, without sharing their passwords. This is possible though a security object known as access token.

If a third-party app wants to connect to the main service, it must get its own access token. The users password is kept safe inside the main service and cannot be obtained from the access token. Access tokens can then be revoked if the user does not want to use the third-party app anymore.

10. Do you have experience with third-party iOS networking libraries? If so, which ones?

The interviewed person could name following libraries:

  • Alamofire - an abstraction layer over URLSession to make networking more simple and elegant
  • Moya - an abstraction layer over Alamofire that creates a type-safe structure for network services and requests

Of course, there are a lot more iOS networking libraries. An extensive list of available libraries maintained by Vinicius Souza is available here.

Related tags

Written by

Articles with related topics