50 iOS Interview Questions And Answers Part 3
Update: September 17 2017.
1- What is Nil Coalescing & Ternary Operator ?
It is an easily return an unwrapped optional, or a default value. If we do not have value, we can set zero or default value.
2- What kind of JSONSerialization have ReadingOptions ?
- mutableContainers Specifies that arrays and dictionaries are created as variables objects, not constants.
- mutableLeaves Specifies that leaf strings in the JSON object graph are created as instances of variable String.
- allowFragments Specifies that the parser should allow top-level objects that are not an instance of Array or Dictionary.
3- Explain subscripts ?
Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the member elements of a collection, list, or sequence.
4- What is DispatchGroup ?
DispatchGroup allows for aggregate synchronization of work. We can use them to submit multiple different work items and track when they all complete, even though they might run on different queues. This behavior can be helpful when progress can’t be made until all of the specified tasks are complete. — Apple’s Documentation
The most basic answer: If we need to wait on a couple of asynchronous or synchronous operations before proceeding, we can use
5- What is RGR ( Red — Green — Refactor ) ?
Red, Green and Refactor are stages of the TDD (Test Driven Development).
- Red: Write a small amount of test code usually no more than seven lines of code and watch it fail.
- Green: Write a small amount of production code. Again, usually no more than seven lines of code and make your test pass.
- Refactor: Tests are passing, you can make changes without worrying. Clean up your code. There are great workshop notes here.
6- Where do we use Dependency Injection ?
We use a storyboard or xib in our iOS app, then we created IBOutlets. IBOutlet is a property related to a view. These are injected into the view controller when it is instantiated, which is essentially a form of Dependency Injection.
There are forms of dependency injection: constructor injection, property injection and method injection.
7- Please explain types of notifications.
There are two type of notifications: Remote and Local. Remote notification requires connection to a server. Local notifications don’t require server connection. Local notifications happen on device.
8- When is a good time for dependency injection in our projects?
There is a few guidelines that you can follow.
Rule 1. Is Testability important to us? If so, then it is essential to identify external dependencies within the class that you wish to test. Once dependencies can be injected we can easily replace real services for mock ones to make it easy to testing easy.
Rules 2. Complex classes have complex dependencies, include application-level logic, or access external resources such as the disk or the network. Most of the classes in your application will be complex, including almost any controller object and most model objects. The easiest way to get started is to pick a complex class in your application and look for places where you initialize other complex objects within that class.
Rules 3. If an object is creating instances of other objects that are shared dependencies within other objects then it is a good candidate for a dependency injection.
9- What kind of order functions can we use on collection types ?
map(_:): Returns an array of results after transforming each element in the sequence using the provided closure.
filter(_:): Returns an array of elements that satisfy the provided closure predicate.
reduce(_:_:): Returns a single value by combining each element in the sequence using the provided closure.
sorted(by:): Returns an array of the elements in the sequence sorted based on the provided closure predicate.
To see all methods available from
Sequence, take a look at the Sequence docs.
10- What allows you to combine your commits ?
11- What is the difference ANY and ANYOBJECT ?
According to Apple’s Swift documentation:
- 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.
12- Please explain SOAP and REST Basics differences ?
Both of them helps us access Web services. SOAP relies exclusively on XML to provide messaging services. SOAP is definitely the heavyweight choice for Web service access. Originally developed by Microsoft.
REST ( Representational State Transfer ) provides a lighter weight alternative. Instead of using XML to make a request, REST relies on a simple URL in many cases. REST can use four different HTTP 1.1 verbs (GET, POST, PUT, and DELETE) to perform tasks.
13- What is you favorite Visualize Chart library ?
Charts has support iOS,tvOS,OSX The Apple side of the cross platform MPAndroidChart.
Core Plot is a 2D plotting framework for macOS, iOS, and tvOS
TEAChart has iOS support
14- Which git command allows us to find bad commits ?
15- What is CoreData ?
Core data is an object graph manager which also has the ability to persist object graphs to the persistent store on a disk. An object graph is like a map of all the different model objects in a typical model view controller iOS application. CoreData has also integration with Core Spotlight.
16- Could you explain Associatedtype ?
If you want to create Generic Protocol we can use associatedtype. For more details check this out.
17- Which git command saves your code without making a commit ?
If high priority thread waits for low priority thread, this is called Priority Inversion. if low priority thread temporarily inherit the priority of the highest priority thread, this is called Priority Inheritance.
19- What is Hashable ?
Hashable allows us to use our objects as keys in a dictionary. So we can make our custom types.
20- When do you use optional chaining vs. if let or guard ?
We use optional chaining when we do not really care if the operation fails; otherwise, we use
if let or
guard. Optional chaining lets us run code only if our optional has a value.
Using the question mark operator like this is called optional chaining. Apple’s documentation explains it like this:
Optional chaining is a process for querying and calling properties, methods, and subscripts on an optional that might currently be nil. If the optional contains a value, the property, method, or subscript call succeeds; if the optional is nil, the property, method, or subscript call returns nil. Multiple queries can be chained together, and the entire chain fails gracefully if any link in the chain is nil.
21- How many different ways to pass data in Swift ?
There are many different ways such as Delegate, KVO, Segue, and NSNotification, Target-Action, Callbacks.
22- How do you follow up clean code for this project ?
23- Explain to using Class and Inheritance benefits
- With Overriding provides a mechanism for customization
- Reuse implementation
- Subclassing provides reuse interface
- Subclasses provide dynamic dispatch
24- What’s the difference optional between
There is no difference.
.None for short) is the correct way of initializing an optional variable lacking a value, whereas
nil is just syntactic sugar for
.None. Check this out.
25- What is GraphQL ?
GraphQL is trying to solve creating a query interface for the clients at the application level. Apollo iOS is a strongly-typed, caching GraphQL client for iOS, written in Swift.
26- Explain Common features of Protocols & superclasses
- implementation reuse
- provide points for customization
- interface reuse
- supporting modular design via dynamic dispatch on reused interfaces
27- What is Continuous Integration ?
Continuous Integration allows us to get early feedback when something is going wrong during application development. There are a lot of continuous integration tools available.
Self hosted server
28- What is the difference Delegates and Callbacks ?
The difference between delegates and callbacks is that with delegates, the NetworkService is telling the delegate “There is something changed.” With callbacks, the delegate is observing the NetworkService.
29- Explain Linked List
Linked List basically consist of the structures we named the Node. These nodes basically have two things. The first one is the one we want to keep. (we do not have to hold single data, we can keep as much information as we want), and the other is the address information of the other node.
Disadvantages of Linked Lists, at the beginning, there is extra space usage. Because the Linked List have an address information in addition to the existing information. This means more space usage.
30- Do you know Back End development ?
Depends. I have experienced PARSE and I am awarded FBStart. I decided to learn pure back end. You have two choices. Either you can learn node.js + express.js and mongodb. OR, you can learn Vapor or Kitura.
Don’t you like or use Firebase?
Firebase doesn't have a path for macOS X developers.
If you want to learn Firebase, please just follow one month of Firebase Google Group.
31- Explain AutoLayout
AutoLayout provides a flexible and powerful layout system that describes how views and the UI controls calculates the size and position in the hierarchy.
32- What is the disadvantage to hard-coding log statements ?
First, when you start to log. This starts to accumulate. It may not seem like a lot, but every minute adds up. By the end of a project, those stray minutes will equal to hours.
Second, Each time we add one to the code base, we take a risk of injecting new bugs into our code.
33- What is Pointer ?
A pointer is a direct reference to a memory address. Whereas a variable acts as a transparent container for a value, pointers remove a layer of abstraction and let you see how that value is stored.
34- Explain Core ML Pros and Cons
Pros of Core ML:
- Really easy to add into your app.
- Not just for deep learning: also does logistic regression, decision trees, and other “classic” machine learning models.
- Comes with a handy converter tool that supports several different training packages (Keras, Caffe, scikit-learn, and others).
- Core ML only supports a limited number of model types. If you trained a model that does something Core ML does not support, then you cannot use Core ML.
- The conversion tools currently support only a few training packages. A notable omission is TensorFlow, arguably the most popular machine learning tool out there. You can write your own converters, but this isn’t a job for a novice. (The reason TensorFlow is not supported is that it is a low-level package for making general computational graphs, while Core ML works at a much higher level of abstraction.)
- No flexibility, little control. The Core ML API is very basic, it only lets you load a model and run it. There is no way to add custom code to your models.
- iOS 11 and later only.
For more information.
35- What is pair programming?
Pair programming is a tool to share information with junior developers. Junior and senior developer sitting side-by-side this is the best way for the junior to learn from senior developers.
36- Explain blocks
Blocks are a way of defining a single task or unit of behavior without having to write an entire Objective-C class. they are anonymous functions.
37- What is Keychain ?
Keychain is an API for persisting data securly in iOS App. There is a good library - Locksmith
38- What is the biggest changes in UserNotifications ?
- We can add audio, video and images.
- We can create custom interfaces for notifications.
- We can manage notifications with interfaces in the notification center.
- New Notification extensions allow us to manage remote notification payloads before they’re delivered.
39- Explain the difference between atomic and nonatomic synthesized properties
atomic : It is the default behaviour. 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. We 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.
40- Why do we use availability attributes ?
Apple wants to support one system version back, meaning that we should support iOS9 or iOS8. Availability Attributes lets us to support previous version iOS.
41- How could we get device token ?
There are two steps to get device token. First, we must show the user’s permission screen, after we can register for remote notifications. If these steps go well, the system will provide device token. If we uninstall or reinstall the app, the device token would change.
42- What is Encapsulation ?
Encapsulation is an object-oriented design principles and hides the internal states and functionality of objects. That means objects keep their state information private.
43- What is big-o notation ?
An algorithm is an impression method used to determine the working time for an input N size. The big-o notation grade is expressed by the highest value. And the big-o notation is finding the answer with the question of O(n). Here is a cheat sheet and swift algorithm club. For example;
For Loops big-o notation is O(N). Because For Loops work n times.
Variables (var number:Int = 4) big-o notation is O(1).
44- What Is Dependency Management?
If we want to integrate open source project, add a framework from a third party project, or even reuse code across our own projects, dependency management helps us to manage these relationships. Check this out
45- What is UML Class Diagrams?
UML Class Diagram is a set of rules and notations for the specification of a software system, managed and created by the Object Management Group.
46- Explain throw
We are telling the compiler that it can throw errors by using the throws keyword. Before we can throw an error, we need to make a list of all the possible errors you want to throw.
47- What is Protocol Extensions?
We can adopt protocols using extensions as well as on the original type declaration. This allows you to add protocols to types you don’t necessarily own.
48- What is three triggers for a local notification ?
Location, Calendar, and Time Interval. A Location notification fires when the GPS on your phone is at a location or geographic region. Calendar trigger is based on calendar data broken into date components. Time Interval is a count of seconds until the timer goes off.
49- Explain Selectors in ObjC
Selectors are Objective-C’s internal representation of a method name.
50- What is Remote Notifications attacment’s limits ?
We can be sent with video or image with push notification. But maximum payload is 4kb. If we want to sent high quality attachment, we should use Notification Service Extension.
- A curated awesome list of iOS interview questions.