iOS Interview Questions Part 1: Differentiate 🎭

iOS Domain is pretty enormous and deep. If you are looking for iOS Development interview questions for the beginner or experienced, then this is the right place. I have prepared some questions and bifurcated in various parts, combining in one story won’t justify this topic.

In this part, we will be differentiating between many known terms in iOS. We come across many terms which seems or sounds similar but are slightly different or completely different. This part will mostly focus on iOS Core development and Objective-C. Swift specific terms will be discussed in separate Part. :)

Q: @synthesis VS @dynamic

@ dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass or will be provided at runtime).

Uses for @dynamic are e.g. with subclasses of NSManagedObject (CoreData) or when you want to create an outlet for a property defined by a superclass that was not defined as an outlet.

Q: XIB VS NIB

NIB(Nxt Interface Builder) is a non-editable and inoperable file. They are smaller in size. These are binary or archive files. After compilation XIB converts into NIB.

Q: NSInteger VS Int VS NSNumber

Int is a primitive data type.

NSNumber stores numeric type as objects and can convert into a different format. It can also retrive a string representation also.

Q: Any VS Anyobject

  • Any can represent an instance of any type at all, including function types and optional types.
  • AnyObject can represent an instance of any class type.

Check out for more details.

Q: Category VS Protocol

Category adds methods to an existing class e.g. NSObject, without modifying the class itself.

Q: Category VS Inheritance

Inheritance also expands the API but introduces a new type. Additionally, subclassing lets you add state and add properties as well

Note: We can add properties in categories through Associated Objects. Check this article by Matt Thompson.

Q: Category VS Extension

Note: Extensions in swift are similar to categories in Objective-C. Unlike Objective-C categories, Swift extensions do not have names.

Extensions (Swift)add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for which you do not have access to the original source code.

Categories(Objc-C only) allow you to add methods outside of the main interface file. Whereas Extensions(Objc-C) must be implemented in the main Interface file. Which means we cannot use extensions for extending Builtin classes or Classes for which you don’t have the source code, there you should use Categories.

Q: Formal VS Informal Protocol

A formal protocol declares a list of methods that client classes are expected to implement. Formal protocols have their own declaration, adoption, and type-checking syntax. You can designate methods whose implementation is required or optional with the @required and @optional keywords. Subclasses inherit formal protocols adopted by their ancestors. A formal protocol can also adopt other protocols.

Note: Apple Docs

Q: NSSet VS NSArray

Q: NSDictionary VS NSMutableArray

Q: Delegate VS Notifications

Delegation also avoids tight coupling. It modifies behavior and appearance without the need of subclass objects.

Q: Shallow VS Deep Copy

Shallow and Deep Copy

Deep Copy is also similar to call by value. It copies actual data and both objects have their own copy i.e they point to a different array. Changes made in one object does not reflect in another one. In Objective-C, it can be implemented by using methods of NSKeyedArchiver/NSKeyedUnarchiver class.

Please check this awesome implementation in Objective-C.

Q: Atomic VS NonAtomic

Non-Atomic is not the default behavior. It is faster (for synthesized code, that is, for variables created using @property and @synthesize). It is not thread-safe and may result in unexpected behavior when two different processes access the same variable at the same time.

What is Thread Safety?
A piece of code is called thread-safe if it gives correct results even in a multi-threaded environment i.e. if it is executed simultaneously by multiple threads it would give the correct result. Thread safety means that the code can handle multiple threads.

Q: Weak VS Strong

In contrast, with a WEAK reference you signify that you don’t want to have control over the object’s lifetime. The object you are referencing weakly only lives on because at least one other object holds a strong reference to it. Once that is no longer the case, the object gets destroyed and your weak property will automatically get set to nil. The most frequent use cases of weak references in iOS are:

  1. delegate properties, which are often referenced weakly to avoid retain cycles, and
  2. subviews/controls of a view controller’s main view because those views are already strongly held by the main view.

Q: Assign VS Weak

  • use assign for primatives — exactly like weak except it doesn’t nil out the object when released, it potentially leaves dangling pointers, ie. will access garbage value. Assign and unsafe_unretained are identical in usage.

Q: Retain VS Strong (=)

  • retain is the same as strong.
  • apple says if you write retain it will auto converted/work like strong only.
  • methods like “alloc” include an implicit “retain”

Q: Retain VS Copy

copy : Makes a copy of an object, and returns it with retain count of 1. If you copy an object, you own the copy. This applies to any method that contains the word copy where “copy” refers to the object being returned.

Q: Bound VS Frame

The frame property contains the frame rectangle, which specifies the size and location of the view in its superview’s coordinate system.

The bounds property contains the bounds rectangle, which specifies the size of the view (and its content origin) in the view’s own local coordinate system.

The center property contains the known center point of the view in the superview’s coordinate system.

Answered by Dan

Q: Nil VS nil VS NSNull

Screenshot from NSHipster

Q: NSNotificationCenter VS local notification VS push notification

NSNotificationCenter: It is internal to the running app and doesn’t require a server or anything special setup. There is no need to get Certificates, Identifiers & Profiles in Apple developer member center. It is used to notify the custom class objects. NSNotification is a message that is sent internally between the objects in the app.

Push Notification: We need to get Certificates, Identifiers & Profiles in Apple developer member center. This indeed requires a server and special setup in the provisioning profile or Info.plist. The message is sent from the server and app handles to display it.

Q: Key-Value Observing VS NSNotificationCenter

NSNotificationCenter adds observers for notifications and used when there are multiple objects are to be notified

Q: isKindOfClass VS isMemberOfClass VS isSubclassOfClass

All of the above return bool value.

[[NSMutableData data] isKindOfClass:[NSData class]]; // YES
[[NSMutableData data] isMemberOfClass:[NSData class]]; // NO
[NSString isSubclassOfClass:[NSObject class]]

Q: Delegate vs target/action

Target/Action are generally used to correspond to an “event-like” situation, such as a click, a timer firing, etc. and is more suitable when the communication is limited to control (events, state, etc). It is mostly manifest 1-Way communication

Q: Content Hugging VS Compression Resistance

Souce: Krakendev

Content Hugging (Content does not want to grow): The higher this priority is, the more a view resists growing larger than its intrinsic content size.

Compression Resistance (Content does not want to shrink): The higher this priority is, the more a view resists shrinking smaller than its intrinsic content size.

Q: GCD VS NSOperation

GCD advantage over NSOperation:
i. implementation
For GCD implementation is very simple, light-weight and have lock free Algo.
NSOperationQueue is complex, heavy-weight and involves a lot of locking

NSOperation advantages over GCD:

i. Control On Operation
you can Pause, Cancel, Resume an NSOperation

ii. Dependencies
you can set up a dependency between two NSOperations
operation will not started until all of its dependencies return true for finished.

iii. State of Operation
can monitor the state of an operation or operation queue. ready ,executing or finished. Can also compute pending operations.

iv. Max Number of Operation
you can specify the maximum number of queued operations that can run simultaneously

v. Observable
The NSOperation and NSOperationQueue classes have a number of properties that can be observed, using KVO (Key Value Observing). This is another important benefit if you want to monitor the state of an operation or operation queue.

When to Go for GCD or NSOperation
when you want more control over queue (all above mentioned) use NSOperation and for simple cases where you want less overhead (you just want to do some work "into the background" with very little additional work) use GCD

Q: Static Vs Dynamic typing

Dynamic typing is when your type checking occurs at runtime. Instead of errors coming up when you compile your code you will get runtime errors if you try performing operations on incompatible types. However, you will get the benefit of having more versatile functions as they can be written once for multiple data types.

Q: What is an “app ID” and a “bundle ID” ?

A bundle ID precisely identifies a single app. It is used during the development process to provision devices and by the operating system when the app is distributed to customers.

During the development process, you use an app’s bundle ID in many different places to identify the app.

Whereas, An App ID is a two-part string used to identify one or more apps from a single development team.

The Team ID is supplied by Apple and is unique to a specific development team, while the bundle ID search string is supplied by you to match either the bundle ID of a single app or a set of bundle IDs for a group of your apps.

There are two types of App IDs: an explicit App ID, used for a single app, and wildcard App IDs, used for a set of apps.

sources: Bundle ID , APP ID

Q: KVC VS KVO?

KVO (Key-Value Observing)- It allows a controller or class to observe changes to a property value. In KVO, an object can ask to be notified of any changes to a specific property, whenever that property changes value, the observer is automatically notified.

Q: BDD VS TDD

Test-Driven Development is a test-first software development methodology, which means that it requires writing test code before writing the actual code that will be tested

Behavior-Driven Development is a methodology that was created based on TDD, but evolved into a process that doesn’t concern only programmers and testers, but instead deals with the entire team and all important stakeholders, technical and non-technical. BDD started out of a few simple questions that TDD doesn’t answer well: how much tests should I write? What should I actually test — and what shouldn’t I? Which of the tests I write will be in fact important to the business or to the overall quality of the product, and which are just my over-engineering?

Some argue that BDD is always better than TDD because it has the possibility of eliminating issues that might arise when using TDD, it isn’t guaranteed to. Issues like poor code organization, bad design practices, etc. will still persist. You’ll just have a lower likely hood of writing bad tests and thus have more robust features.

iOS BDD Framework: Quick & Nimble.

Q: SVN VS Git

Git relies on a distributed system for version management. You will have a local repository on which you can work, with a network connection only required to synchronise.

Q: JSON VS XML

Souce: freefeast

Q: Rest VS Soap

Q: Stack VS Heap

With Heap, variable can be accessed globally, but have slow access. It has no memory limit. There is no guaranteed efficient use of space, memory may become fragmented over time as blocks of memory are allocated, then freed. We need to manage memory.

More info.

Q: Static VS Dynamic Library

Static libraries allow an application to load code into its address space at compile time.This results in a larger size on disk and slower launch times. Because the library’s code is added directly to the linked target’s binary, it means that to update any code in the library, the linked target would also have to be rebuilt.

Dynamic Library(.dylib)

Dynamic libraries allow an application to load code into its address space when it’s actually needed at run time. Because the code isn’t statically linked into the executable binary, there are some benefits from loading at runtime. Mainly, the libraries can be updated with new features or bug-fixes without having to recompile and relink executable. In addition, being loaded at runtime means that individual code libraries can have their own initializers and clean up after their own tasks before being unloaded from memory

Q: SQLite vs Core data

Core Data: Primary function is graph management (although reading and writing to disk is an important supporting feature). It operates on objects stored in memory. It works with fully-fledged objects that self-manage a lot of their behavior and can be subclassed and customized for further behaviors. It is also non-transactional, single threaded, single user. It requires a save process and leaves data constraints to the business logic side of the program

Q: CollectionViews VS TableViews

CollectionViews also display a list of items, however, they can have multiple columns and rows.

Q: LLVM VS Clang

Front end ( Clang ) takes the source code and generates abstract syntax tree ( LLVM IR ).

Q: Property VS Instance Variable

For an iVar, you can use @private, @protected and @public. But these attributes only influence the access of its subclass, and has nothing to do with the access ability of its instances.

iVar is faster than property, as property will call the getter or setter functions. When you declare a property, the compiler will add getter and setter functions for the property.

iVar is an instance variable. It cannot be accessed unless we create accessors, which are generated by @property. iVar and its counterpart @property can be of different names. iVar is always can be accessed using KVC.

Note for property inheritance: If the super class has a property declared as public, the subclass can inherit the property. But the auto synthesize mechnism will not sythesize the property automatically, and you can only use the getter and setter accessors of the superclass by using dot operation. If you want to synthesize manually, Be Carefull! You should avoid using the same iVar as them in the superclass. This will lead to an error message “property ‘propertyName’ atemping to use instance variable ‘InstanceVariableName’ declared in super class ‘SuperClassName’”.

Q: SDK VS Framework

Q: ARC VS AutoRelease

Where to go next — Part 2 ObjectiveC