iOS Interview Questions And Answers

iOS Interview Questions And Answers

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.

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.

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.

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.

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.

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.

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

To avoid retain cycles and memory leaks.

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.

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.

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.

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.

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.

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.

What is a managed object context ?

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

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.

What is the purpose of the reuseIdentifier ?

Reusability of an already allocated object.

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.

Define atomic and nonatomic.

Atomic is the default: if you don’t type anything, your property is atomic. An atomic property is guaranteed that if you try to read from it, you will get back a valid value. It does not make any guarantees about what that value might be, but you will get back good data, not just junk memory. What this allows you to do is if you have multiple threads or multiple processes pointing at a single variable, one thread can read and another thread can write. If they hit at the same time, the reader thread is guaranteed to get one of the two values: either before the change or after the change. What atomic does not give you is any sort of guarantee about which of those values you might get. Atomic is really commonly confused with being thread-safe, and that is not correct. You need to guarantee your thread safety other ways. However, atomic will guarantee that if you try to read, you get back some kind of value.

On the flip side, non-atomic, as you can probably guess, just means, “don’t do that atomic stuff.” What you lose is that guarantee that you always get back something. If you try to read in the middle of a write, you could get back garbage data. But, on the other hand, you go a little bit faster. Because atomic properties have to do some magic to guarantee that you will get back a value, they are a bit slower. If it is a property that you are accessing a lot, you may want to drop down to nonatomic to make sure that you are not incurring that speed penalty.

If you want to know more about this check this article

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.

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.

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.

View story at


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s