25 iOS interview questions and answers for junior developers.

Let me throw in the disclaimer, however, that it is still too early to tell. As you will see during this or future posts, English it’s not my first language, so please if you are sensitive to grammatical crimes this is the best time for you to leave this page, I won’t take it personal and not feelings will be hurt.

Phhhhhhhiiwww, having said this and with no more guilt in my conscience lets deep in  what really matters.

I am junior IOS developer, a self-taught one, no computer science degree but with a lot of curiosity and passion for coding, I just finished an iOS Bootcamp in San Francisco called Mobile Makers, and worked for two startups helping develop new features for their apps. I am currently working on freelance projects but I am actively looking for a more stable job.

Like many developers new to the field as myself,  I am  currently in the excruciating period of my life called “been interviewed for a tech position”;  that’s right… long phone calls, whiteboard tests all the fun stuff. One wrong answer during your first interviews can determine  if you get the job, or  just a “thank you for participate” email.

That’s why as a practice for me (sometimes you learn “teaching” right?) I want to share a nice collection of iOS questions that I’ve been collecting from interviews with companies like Wells Fargo, Facebook and from online forums and  sites.

1 – What is a memory leak?

A memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations  in such a way that memory which is no longer needed is not released. In object-oriented programming, a memory leak may happen when an object is stored in memory but cannot be accessed by the running code.

2 – Describe what “app thinning” means ?

The store and operating system optimize the installation of iOS, tvOS, and watchOS apps by tailoring app delivery to the capabilities of the user’s particular device, with minimal footprint. This optimization, called app thinning, lets you create apps that use the most device features, occupy minimum disk space, and accommodate future updates that can be applied by Apple.

3 – What is auto-layout?

Auto Layout dynamically calculates the size and position of all the views in your view hierarchy, based on constraints placed on those views.

4 – What is GCD? How is it used?

GCD is the most commonly used API to manage concurrent code and execute operations asynchronously at the Unix level of the system. GCD provides and manages queues of tasks. A good example is when an App fetch data from an API, this network call should be done in a background thread and the display of the data in the view should be executed in the main thread as well as any UI updates.

5 – What are the benefits of Swift over Objective-C ?

  • Swift is easier to read. (mmm really?)
  • Swift is easier to maintain.
  • Swift is safer.
  • Swift is unified with memory management.
  • Swift requires less code.
  • Swift is faster.
  • Fewer name collisions with open source projects.
  • Swift support dynamic libraries.
  • Swift Playgrounds encourages interactive coding.
  • Swift is a future you can influence.

Here is a link where you can see these assertions in detail.

6 – What is Synchronous vs. Asynchronous in GCD ?

These terms describe when a function will return control to the caller, and how much work will have been done by that point.

A synchronous function returns only after the completion of a task that it orders.

An asynchronous function, on the other hand, returns immediately, ordering the task to be done but not waiting for it. Thus, an asynchronous function does not block the current thread of execution from proceeding on to the next function.

7 – Why do you generally create a weak reference when using self in a block?

To avoid retain cycles and   memory leaks.

8 – What is the GCD method you call to pass some work to a queue asynchronously? What parameters do you provide to this method?
dispatch_async(dispatch_get_main_queue(), ^{ });
We pass as a parameter the dispatch queue where we want to execute the code.

9 – What are some ways to support newer API methods or classes while maintaining backward compatibility? For instance, if you want your view to have a red tintColor (a method introduced in iOS 7), but your app still supports iOS 6, how could you make sure it won’t crash when running on iOS 6? Another example would be using NSURLSession vs. NSURLConnection – how could you make it so that your code uses the most appropriate of those two classes?

    • Treat deprecated APIs warnings as errors to resolve.
    • At runtime, check for OS versions.
    • objC : Mark legacy code paths with macros.

if #available(iOS 8, *, *) {
self.view.convertPoint(.Zero, toCoordinateSpace:anotherView)
} else {
self.view.convertPoint(CGPointZero, toView:anotherView)
}

  • Control the number of 3d party libraries.

You can see this topic in more detail here.

10 – What is MVC ?

MVC is a design pattern that stands for model view controller, this design pattern separates the data from its display, mediated by a View Controller.

11 – What are delegates ?

Delegates are a design pattern. A delegate is just an object that another object sends messages to when certain things happen so that the delegate can handle app-specific details the original object wasn’t designed for. It’s a way of customizing behavior without subclassing. And it’s important to remember that they have one to one relationship.

12 – What are NSNotificationCenter and how does it work ?

NSNotificationCenter is what Apple has provided as an Observer Pattern in the Cocoa library . The basic idea is that a listener registers with a broadcaster using some predefined protocol. At some later point, the broadcaster is told to notify all of its listeners, where it calls some function on each of its listeners and passes certain arguments along. This allows for asynchronous message passing between two different objects that don’t have to know about one another, they just have to know about the broadcaster.

13 – What is Core Data ?

Core Data is not an ORM or object-relational mapper. Nor is it a database. Instead, Core Data is an object graph manager which also has the ability to persist object graphs to a persistent store, on a disk.

14 – What is a managed object context ?

A managed object context represents a single object space, or scratch pad, in a Core Data application.

15 – Difference between frame and bounds ?

The frame relates a view’s location and size in its parent View.

The bounds relate a view’s location and size using its own coordinate system.

16 – What is the purpose of the reuseIdentifier ?

Reusability of an already allocated object.

17 –  How many UITableViewCells are allocated when you first load a UITableView? How many additional ones are allocated as you scroll through the table?

A UITableView  will normally allocate just enough UITableViewCell objects to display the content visible in the table. Because of the reuseIdentifier , the UITableView will not  allocate new UITableViewCell  objects for each new item that scrolls into view, avoiding  laggy animations.

18 – Define atomic and nonatomic.

  • atomic : It is the default behavior. If an object is declared as atomic then it becomes thread-safe. Thread-safe means, at a time only one thread of a particular instance of that class can have the control over that object.
  • nonatomic: It is not thread-safe. You can use the nonatomic property attribute to specify that synthesized accessors simply set or return a value directly, with no guarantees about what happens if that same value is accessed simultaneously from different threads. For this reason, it’s faster to access a nonatomic property than an atomic one.

19 – Whats the difference between weak and strong ?

These keywords are related to reference counting and “denote ownership”, if you will. They help you eliminate retain-release cycles by limiting what objects increment the reference count for another object. A strong property is one where you increment the reference count of the object. If object A has a strong reference to B, and no other object is referencing B, B has count 1 (A owns, or needs to exist B). Now, if B wants to have a reference to A, we would want to use a weak reference. Weak references don’t increment the reference count of the object. So in this particular case, if A has no other objects referencing it but B, A’s count would be 0 given B’s weak reference.

20 – What’s the difference between not-running, inactive, active, background and suspended execution states?

  • Not running: The app has not been launched or was running but was terminated by the system.
  • Inactive: The app is running in the foreground but is currently not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state.
  • Active: The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.
  • Background: The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state.
  • Suspended: The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code. When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.

21 – What is a category and when is it used ?

A category is a way of adding additional methods to a class without extending it. It is often used to add a collection of related methods. A common use case is to add additional methods to built-in classes in the Cocoa frameworks.

22 – What is the difference between viewDidLoad and viewDidAppear? Which should you use to load data from a remote server to display in the view?

viewDidLoad is called when the view is loaded, whether from a Xib file, storyboard or programmatically created in loadView. viewDidAppear is called every time the view is presented on the device. Which to use depends on the use case for your data. If the data is fairly static and not likely to change then it can be loaded in viewDidLoad and cached. However, if the data changes regularly then using viewDidAppear to load it is better. In both situations, the data should be loaded asynchronously on a background thread to avoid blocking the UI.

23 – What’s the difference between using a delegate and notification?

Both are used for sending values and messages to interested parties. A delegate is for one-to-one communication and is a pattern promoted by Apple. In delegation, the class raising events will have a property for the delegate and will typically expect it to implement some protocol. The delegating class can then call the delegates protocol methods.

Notification allows a class to broadcast events across the entire application to any interested parties. The broadcasting class doesn’t need to know anything about the listeners for this event, therefore notification is very useful in helping to decouple components in an application.

24 – What happens when you invoke a method on a nil pointer ?

A message sent to a nil object is perfectly acceptable in Objective-C, it’s treated as a no-op. There is no way to flag it as an error because it’s not an error, in fact, it can be a very useful feature of the language.

25 – Which is faster: to iterate through an NSArray or an NSSet?

When the order of the items in the collection is not important, NSSet offers better performance for finding items in the collection; the reason is that the NSSet uses hash values to find items (like a dictionary), while an array has to iterate over its entire contents to find a particular object.

Wow…  that’s a lot of questions right? don’t worry, not even the most experienced developer knows everything, the important is to be familiarized with some basic topics that will give you confidence during an interview, and that will give your potential employer the confidence to hire you, of course.

So, if you are currently interviewing for a junior position and had been asked for something that it’s not on this list, please share it in the comments!

I hope this help you.

Peace!

Advertisements

6 thoughts on “25 iOS interview questions and answers for junior developers.

  1. This is exactly my story of iOS job interviews. Almost the same questions. Good post. Great job leaving the answers available to everyone. I would just add a couple of questions more (I’m in a hurry so, I won’t leave answers, but they are pretty easy to find):
    1) Key word ‘retain’?
    2) What are setter & getter and what they have in common with key word ‘synthesize’?
    3) What is a Class?
    4) What does the prefix NS means?
    5) Memory management – What is heap and what is a stack?
    6) Memory management – ARC (automatic reference counting) vs MRR (Manual Retain Release)? (not important if you qualify for Swift directly and not Obj-C)
    7) Define singleton.
    8) Define and explain enumeration.
    9) Explain encapsulation?

    Master all these, and you’re ready for your iOS job interview. Good Luck, juniors ❤

    Liked by 1 person

    1. Hi Nikola, thank you very much for leave this questions, I wanted to take some time to answer them, hope the answers make sense for you😉

      1) Key word ‘retain’?
      – The retain keyword is what developers used before ARC, to manage reference counting. “Retain” Increases the retain count of an object by 1, and takes ownership of the object. With ARC we not longer use retain in our properties, we use “strong” instead.
      2) What are setter & getter and what they have in common with key word ‘synthesize’?
      – Setters and getters in objective-c are basically what the name implies. With a setter method, you set the method to declare/initialize it. With a getter method, you can access the value you set from anywhere in your code.
      @synthesize was used to link a property with an internal class variable. It’s done automaticaly with ARC.
      3) What is a Class?
      – As in many other object-oriented programming languages, Objective-C /Swift classes provide the blueprint for creating objects. First, you define a reusable set of properties and behaviors inside of a class. Then, you instantiate objects from that class to interact with those properties and behaviors.
      4) What does the prefix NS means?
      – It’s from the NeXTSTEP heritage.
      5) Memory management – What is heap and what is a stack?
      – Stack is used for static memory allocation and Heap for dynamic memory allocation, both stored in the computer’s RAM. Review this link for a more extensive answer https://www.quora.com/What-is-the-difference-between-the-stack-and-the-heap
      6) Memory management – ARC (automatic reference counting) vs MRR (Manual Retain Release)? (not important if you qualify for Swift directly and not Obj-C)
      – When iOS was first launched, it made use of a type of manual memory management; iOS doesn’t have garbage collection, it uses reference counting, and before ARC the developer had to handle the release of the objects manually. With ARC the reference
      counting is happening automatically, doesn’t mean you’re immune to memory management problems.
      You still need to write code that considers memory issues, and
      also know how to track down memory related problems when they arise.
      7) Define singleton.
      – A singleton class returns the same instance no matter how many times an application requests it. A singleton object provides a global point of access to the resources of its class. Singletons are used in situations where this single point of control is desirable, such as with classes that offer some general service or resource.
      8) Define and explain enumeration.
      – Enumeration is the process of sequentially operating on elements of an object—typically a collection—each at most once, one at a time in turn. Enumeration is also referred to as iteration.
      9) Explain encapsulation?
      – Encapsulation is an Object-Oriented Programming concept that binds together the data and functions that manipulate the data and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding.

      Cheers!

      Like

  2. Thanks for the article. Was useful… Here are some from me..

    *How many ways you know to persist data? Types?
    *How many ways you know to achieve concureency? Types?
    *Differences between Manual and Automatic Reference Counting
    *Design Patterns

    Liked by 1 person

  3. Hello Petko, glad you find it useful and thank you for your questions, let me provide some answers for them 😉

    *How many ways you know to persist data? Types?
    – This choice will depend on what you want to achieve in your application, you can save data in CoreData, SqlLite or NSUserDefaults, Realm is also an option these days.

    *How many ways you know to achieve concurrency? Types?
    There are basically three ways of achieving concurrency in iOS:
    – threads
    – dispatch queues
    – operation queues
    The disadvantage of threads is that they relegate the burden of creating a scalable solution to the developer. You have to decide how many threads to create and adjust that number dynamically as conditions change. Also, the application assumes most of the costs associated with creating and maintaining the threads it uses.
    OS X and iOS, therefore, prefer to take an asynchronous design approach to solving the concurrency problem rather than relying on threads.
    One of the technologies for starting tasks asynchronously is Grand Central Dispatch (GCD) that relegates thread management down to the system level. All the developer has to do is define the tasks to be executed and add them to the appropriate dispatch queue. GCD takes care of creating the needed threads and scheduling tasks to run on those threads.
    All dispatch queues are first-in, first-out (FIFO) data structures, so tasks are always started in the same order that they are added.
    An operation queue is the Cocoa equivalent of a concurrent dispatch queue and is implemented by the NSOperationQueue class. Unlike dispatch queues, operation queues are not limited to executing tasks in FIFO order and support the creation of complex execution-order graphs for your tasks.

    *Differences between Manual and Automatic Reference Counting
    – When iOS was first launched, it made use of a type of manual memory management; iOS doesn’t have garbage collection, it uses reference counting, and before ARC the developer had to handle the release of the objects manually. With ARC the reference
    counting is happening automatically, doesn’t mean you’re immune to memory management problems.
    You still need to write code that considers memory issues, and
    also know how to track down memory related problems when they arise.

    *Design Patterns
    Most common design patterns :
    – Singletons .- A singleton encapsulates a unique resource and makes it readily accessible throughout the application.
    – KVC .- KVC or Key-Value-Coding is a generic way of accessing an object’s properties and variables by using a dictionary style interface.
    – Notifications.- Notifications are a mechanism for broadcasting a simple message throughout an application.
    – MVC .- MVC defines the relationship between subsystems composed of classes or, more generally, source modules.
    – Delegation.- A delegate is for one-to-one communication and is a pattern promoted by Apple. In delegation, the class raising events will have a property for the delegate and will typically expect it to implement some protocol. The delegating class can then call the delegates protocol methods.

    Cheers!

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s