50 iOS Interview Questions And Answers Part 5
Update: January 12, 2019
Hello, Part 5 is ready !
These series’ purpose is for helping everyone who has an idea to change job or preparing next big step their lives.
But I really want to tell you something. You have to be ready for a code challenge for an on-site interview without your MacBook.
1- Explain Data Structures
Arrays, Sets, Tuples, and Dictionaries are all collections of data structures that store data in one place.
2- Explain CodingKey Protocol
CodingKeys enum ( Protocol ) lets you rename specific properties in case the serialized format doesn’t match the requirements of the API. CodingKeys should have nested enum.
3- Explain IGListKit
IGListKit provides automatically diff objects to create insertions, deletions, and moves before performing batch updates on the collection view. If a user deletes an update in the queue we’re viewing, we’ll see it fade out without requiring a pull down to refresh.
We say goodbye to UICollectionViewDatasource, and instead use an IGListAdapter with a IGListAdapterDataSource. The data source doesn’t return counts or cells, instead it provides an array of Section Controllers. Section Controllers are then used to configure & control cells within the given collection view section.
4- What is URLSession?
When we want to retrieve contents from certain URL,we choose to use URLConnection. There are three types of tasks:
Data tasks: getting data to memory
Download tasks: downloading file to disk
Upload tasks: uploading file from disk and receiving response as data in memory
5- How do we download images?
With URLSession, we can download an image as a data then convert it from NSData to UIImage lastly we connect it UIImageView IBOutlet. Better way is to use a library. Also with URLSession Adaptable Connectivity API we can built-in connectivity monitoring and run a request, if there is no connection. Request will wait and download whenever the resource is available instead of failing.
6- How does TestFlight make a difference?
- Multiple builds distribution
- Testing groups
- Internal auto distribution
- Tester metrics
- Increased to 10,000 test users
- Public Link
7- What is SnapKit or Masonry make a difference from Auto layout?
8- Explain IteratorProtocol
IteratorProtocol protocol is tightly linked with the
Sequence protocol. Sequences provide access to their elements by creating an iterator, which keeps track of its iteration process and returns one element at a time as it advances through the sequence. There are very good examples on the differences of
IteratorProtocol from for loop and while loop.
9- Explain differences between WKWebView and UIWebView
WKWebView has own cookie storage and its not share by the whole app and all other web views like in the case of (UIWebView).
10- Explain XLIFF Pros and Cons
- It helps us to extract the localization work from or code so we don’t have to make any language assumptions in your source code.
- XLIFF files also holds the content to be localized from our development language along with the translations.
- XLIFF consolidates strings from different resources and different file types into one single document.
- XLIFF does not give them that visual and functional context.
- XLIFF does not provide the resource data like assets in your project.
- XLIFF does not provide with the custom metadata about the generated XLIFF.
11- What is difference Layout Margins and Directional Layout Margins ?
- Layout Margins property of a UIView is of type UIEdgeInsets and defines the top, left, bottom and right insets that when applied to the view’s frame define the view’s margin.
- Directional Layout Margins that are aware of Right-To-Left (RTL) languages. This follows the pattern used when creating constraints with layout anchors. See this earlier post about RTL Languages.
12- What is Sequence protocol ?
13- What is OAuth ?
OAuth short for Open Authorization, is an authorization protocol and not one used for authentication. OAuth being an authorization protocol, isn’t concerned with identifying the user. Instead it deals with the authorization of a third party application to access user data without exposing the user’s credentials. There are two libraries:
14- What is offset ?
If we want to arrange the button at Bottom-Right of superview with spacing 20 Pts, we use view attribute of UIButton or UILabel for reference to view attribute of superview and use .offset(x) for set padding.
15- Explain rethrows keyword
rethrows is a pretty special keyword that you can use in conjunction with closures that can throw errors.
The rethrows keyword indicates to the compiler that the outer function is a throwing function only if the closure passed in throws an error that is propagated to the current scope.
Basically with rethrows, we can use throw inside the closure. When the error handlers are called within the function we use throws.
16- Explain @objc inference
We can tag a Swift declaration with @objc to indicate that it should be available to Objective-C. In Swift 3 many declarations were automatically inferred to be made available to Objective-C. The most common place for this is any Swift method we want to refer to using a selector.
17- What is Safe area ?
Safe area allows us to create constraints to keep our content from being hidden by UIKit bars like the status, navigation or tab bar. Previously we used
18- Explain Viper Architecture
Viper is an another design patters. It has five layers: View, Interactor, Presenter, Entity, and Router. It is based on Single Responsibility Principle.
Advantages of Viper architecture is communication from one entity to another is given through protocols. The idea is to isolate our app’s dependencies, balancing the delegation of responsibilities among the entities.
You can find more details in this article.
19- Explain Content offset
When we scroll a scrollView, it modifies a property known as content offset. Content offset is a point at which the origin of the contentView, that is the bounds rectangle, is offset from the origin of the scrollView.
Using this value, the scrollView can compute its new bounds and redraw any of its subviews.
20- Explain Queues
Queues are used to store a set of data, but are different in that the first item to go into this collection, will be the first item to be removed. Also well known as FIFO which means, ‘first in first out’.
21- Explain @objcMembers inference
When we declare this class as having @objcMembers everything in the class will be exposed to the Objective-C runtime. This is the same as writing implicitly @objc in front of the function.
22- What’s new with Xcode Server ?
There are a few improvements:
- Xcode Server no longer need macOS Server app, it’s now built inside Xcode 9.
- Continuous integration bots can be run on any Mac with Xcode 9, no need to install macOS Server.
23- Explain type inference
Swift uses type inference to work out the appropriate type. Type inference enables a compiler to deduce the type of a particular expression automatically when it compiles your code, simply by examining the values you provide.
24- What is the difference between Array vs NSArray ?
Array can only hold one type of data, NSArray can hold different types of data. The array is value type, NSArray is immutable reference type.
25- What is NSLayoutAnchor ?
With iOS 9, Apple introduced the
NSLayoutAnchor class to make writing autolayout easier with code.
There are three subclasses of
NSLayoutXAxisAnchorThis subclass is used to create horizontal constraints
NSLayoutYAxisAnchorThis subclass is used to create vertical constraints
NSLayoutDimensionThis subclass is used to create the width and height constraints
26- What is the
mutating keyword ?
mutating keyword is used to let variables be modified in a
27- What is snapshot testing ?
Snapshot testing is a way to automatically test the aesthetic part of your UI. It consists of creating a view from your app and comparing it against a reference image.
28- What is circular dependencies ?
A circular dependency is a relation between two or more modules which either directly or indirectly depend on each other to function properly. Such modules are also known as mutually recursive.
29- What’s the difference between MKAnnotation and MKPointAnnotation?
MKAnnotation is a protocol. Typically, we will create a NSObject subclass that implements this protocol. Instances of this custom class will then serve as your map annotation.
MKPointAnnotation is a class that implements MKAnnotation. We can use it directly if we want our own business logic on the annotation.
30- What is DTO ?
DTO is widely used in web projects. It declares the response to the
Mappable protocol. It contains the implementation of the
mapping(map: Map) function.
31- Explain Main Thread Checker
The Main Thread Checker is a new tool launched with Xcode 9 which detects the invalid use of Apple’s frameworks like UIKit, AppKit etc that supposed to be used from main thread but accidentally used in the background thread. The effect of the invalid usage can result in missed UI updates, visual defects, data corruption, and crashes. You can read more about the Main Thread Checker here.
32- What is the difference Stack and Heap ?
Our code takes up some space in the iOS. The size of this is sometimes fixed and sometimes it can change according to what the user will enter during the program. Basically we have two different methods because of this difference: Stack and Heap
Stack is used and automatically removes itself from memory after work is finished. But in Heap the user could do it by writing manual code for deleting from memory.
- Stack is easy to use.
- It’s kept in RAM on the computer.
- Created variables are automatically deleted when they exit the stack.
- It is quite fast compared to Heap.
- Constructed variables can be used without a pointer.
- Compared to Stack, it is quite slow.
- It creates memory problems if not used correctly.
- Variables are used with pointers.
- It is created at runtime.
33- Explain VIP ( Clean-Swift) Architecture
ViewController interacts directly with an Interactor by sending Requests to it. The Interactor responds to those requests by sending a Response with data model to a Presenter. The Presenter formats data to be displayed, creates a ViewModel and notifies the ViewController that it should update its View based on the ViewModel. ViewController decides when the navigation to a different scene should happen by calling a method on a Router. The Router performs setup of the next View Controller and deals with wiring, passing data and delegation setup.
When compared to VIPER, difference is that the ViewController itself contacts Router for navigation.
Please check out this project.
34- Explain UIBezierPath
UIBezierPath class allows us define custom paths that describe any shape, and use those paths to achieve any custom result we want.
35- Explain Dependency Injection Container
The container keeps a map of each class type to an instance of that class. We can then instantiate any class by simply providing the type to the container. The container then automatically provides dependencies for the class.
36- Explain ObjectMapper for parsing JSON data
ObjectMapper converts JSON data to strongly typed model objects. It has a two-way binding between JSON and deal with generic object and nested objects. Also we can manage subclasses.
37- Explain CAShapeLayer
CAShapeLayer is a CALayer subclass, its provides hardware-accelerated drawing of all sorts of 2D shapes, and includes extra functionality such as fill and stroke colors, line caps, patterns and more. Check out for more details.
38- Explain Get Request Steps
We’re going to create the task. We’re going to receive the data back from the server. And we’re going to handle it based on if there’s any errors and what the data is.
39- Explain coordinate systems in views
UIkit defines a default coordinate system with the origin in the top left corner, and axis extending to the right, and down from the origin point. Views are laid out within this coordinate system to position and size them.
In addition to this Default Coordinate System, which we’ll call the Screen Coordinate System, an app’s window and views also define their own Local Coordinate System.
For example single view, a view object tracks its size and location using a frame and bounds. A frame is a rectangle, which specifies the size and location of the view within its SuperView coordinate system.
A bounds rectangle, on the other hand, specifies the size of the view within its own local coordinate system. Please remember part 1.
40- Explain Encoding, Decoding and Serialization, Deserialization
Serialization is the process of converting data into a single string or json so it can be stored or transmitted easily. Serialization, also known as encoding. The reverse process of turning a single string into a data is called decoding, or deserialization. In swift we use
Codable protocol that a type can conform to, to declare that it can be encoded and decoded. It’s basically an alias for the
41- What is the purpose of using IBAction and IBOutlet ?
IBOutlet are macros defined to denote variables and methods that can be referred to in Interface Builder.
IBAction resolves to
IBOutlet resolves to nothing, but they signify to Xcode and Interface builder that these variables and methods can be used in Interface builder to link UI elements to your code.
42- Explain AlamoFire Benefits
- AlamoFire creates a route. This means we can create the request and execute it to the server by one static function.
- AlamoFire provides method chaining for the requests that’s returned, which makes it easy for adding headers,and handling responses.
- AlamoFire has multiple response handlers hat’s returned in binary form, text, parse JSON, and we can even use multiple of these for a given request.
- AlamoFire has the method chaining allows for response validation. We can call validation to check for the status code of the HTTP response, the content type, or any custom validation you might need to do for our app.
- AlamoFire gives us that use a couple of protocols, URLConvertible, and URLRequestConvertible. These protocols can be passed in when creating a request.
- AlamoFire provides extensions can be passed in to create the request.
43- Explain Semaphore in iOS
When we do thread operations on iOS, it works. The application is quite effective in preventing data from interfering with different processes while downloading data to the device. Or we can time out the process by checking the wait time.
As a structure, more than one working process is kept waiting according to the situation and the other process are engaged in the processes such as entering the circuit when completed.
44- What is LLDB?
45- Explain Tuples
Tuples are a compound type in Swift, that means we can hold multiple values like a structure. Tuples hold very value types of data but we created data structures (like dictionaries).
46- Explain the difference between Generics and AnyObject in Swift
Generics are type safe, meaning if you pass a string as a generic and try to use as a integer the compiler will complain and you will not be able to compile your. Because Swift is using Static typing, and is able to give you a compiler error.
If you use AnyObject, the compiler has no idea if the object can be treated as a String or as an Integer. It will allow you to do whatever you want with it.
47- Explain Dependency Inversion Principle
Dependency Inversion Principle serves to decouple classes from one another by explicitly providing dependencies for them, rather than having them create the dependencies themselves.
48- What is Smoke Testing?
Smoke Testing, also known as “Build Verification Testing”, is a type of software testing that comprises of a non-exhaustive set of tests that aim at ensuring that the most important functions work.
The term ‘smoke testing’, it is said, came to software testing from a similar type of hardware testing, in which the device passed the test if it did not catch fire (or smoked) the first time it was turned on.
49- Explain how does UIEdgeInsetsMake work?
According to the documentation: We can use this method to add cap insets to an image or to change the existing cap insets of an image. In both cases, you get back a new image and the original image remains untouched. We use the amount of pixels what we want to make unstretchable in the values of the
UIEdgeInsetsMake function. Goal is to keep original rounded corners of image. With UIEdgeInsets, we can specify how many pixels to the top, left, bottom, and right stretching the image.
UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0)
50- What is the meaning of id ?
id is a pointer to any type, it always points to an Objective-C object. The
AnyObject protocol is similar and it helps bridge the gap between Swift and Objective-C.