50 iOS Interview Questions And Answers Part 6

Image for post
Image for post
The National Gallery of Art

The long wait is over! Here is Part 6 of the series of 50 iOS Interview Questions. Check out Part 1, Part 2, Part 3, Part 4 and Part 5 if you haven’t already :). Let’s get started.

1- Why it is better to use higher-order functions?
Functions that take another function as a parameter, or return a function, as a result, are known as higher-order functions. Swift defines these functions as CollectionType.

The very basic higher-order function is a filter.

2- Explain Mediator Design Pattern

Mediator object encapsulates the interaction policies in a hidden and unconstraining way. Objects being manipulated by mediator have no idea it exists. It sits quietly behind the scenes and imposes its policies without their permission or knowledge.

If you want to learn more about this pattern, I recommend checking the Mediator Pattern Case Study.

3- What is Result Bundle?

According to Apple, Result Bundle is a file produced by Xcode containing structure data describe to auto come of the building running your test. It contains Build log, test report, code coverage report, and test attachments.

4- Explain NSLinguisticTagger

NSLinguisticTagger is an API for natural language processing which allows us to tokenize text, detect the language, and determine parts of speech. NSLinguisticTagger recognizes words and tell us what kind of word that is.

5- Explain XCUIDevice

XCUIDevice simulates physical buttons and device orientations for architecting tests on iPhones and iPads.

6- Explain UIKit Dynamics

UIKit Dynamics is a 2D physics-inspired animation system designed with a high-level API, allowing us to simulate the physical experiences in our animations and view interactions.

7- What is the difference between UIKit and SwiftUI ?

UIKit is an imperative event-driven framework for building User Interfaces for iOS platform. SwiftUI is a declarative framework for building User Interfaces for building User Interfaces for Apple platform.

8- Explain Implicit Expression

Implicit Expression well-known name is Implicit Member Expression which is a way to access a member of a type. We use it to prevent global constant usage.

9- Explain subscripts

Subscripts are analogous to methods. Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the member elements of a collection, list, or sequence.

10- What is the difference between CustomStringConvertible and CustomDebugStringConvertible?

If the value is a String, return that value. If the value is CustomStringConvertible or CustomDebugStringConvertible, return String(reflecting:)

11- What are bundles?

Bundles are how iOS represents our executable code and other resources stored on our drive. Most important thing is, bundles are responsible for loading the localized strings used by your app.

12- Explain App Store Connect API

App Store Connect API was announced in WWDC 2018. App Store Connect API is a standard RESTful API. API used JSON Web Tokens for authentication and can be accessed from all platforms.

We can automate managing certificates, provisioning profiles, managing device ID and bundle ID, users, roles, TestFlight, and Public Links.

13- What are B-Trees?
B-trees are search trees that provide an ordered key-value store with excellent performance characteristics. In principle, each node maintains a sorted array of its own elements and another array for its children.

14- Explain tokenization

Tokenizing a string denotes splitting a string with respect to a delimiter. Check this example usage for Swift.

15- Explain Swift asserts

If we need to check our code for some kind of condition, we can use asserts. The assertions are a neat debugging tool. Assertions are for checking errors for developers. There are five assertion functions int the Standart Swift library.

According to Apple’s Swift documentation:

We use asserts to make sure an essential condition is satisfied before executing any further code.

16- Explain UICollectionViewFlowLayout

UICollectionViewFlowLayout is automatically trying to fit in as many items as it can within a line before it wraps to the next one. We can get multiple columns if we change our item size.

I highly recommend watching A Tour of UICollectionView

17- Explain the difference between a while loop and repeat while

A while loop checks the condition before the loop code, whereas repeat while checks the condition after. If we want to check each time to see the condition is true, we have to use for in loop.

18- Explain CustomStringConvertible and its difference from CustomDebugStringConvertible

We can use custom string description of our objects implementing the CustomStringConvertibleprotocol and adding a new computed property called description

CustomDebugStringConvertible provides additional information about our objects, for debugging purposes.

19- Explain Thread Sanitizer

Enabling Thread Sanitizer allows us to debug data races when multiple threads try to access the same memory area in a nonatomic way and with at least one write operation in one of those threads.

Thread Sanitizer is only supported for 64-bit macOS and 64-bit iOS and tvOS simulators. watchOS is not supported.

Thread Sanitizer | Apple Developer Documentation

20- Explain Bridging Headers in iOS project

Bridging Headers allow us to include Objective-C files with our Swift files.

21- Why would we use multiple projects in the workspace?

Framework and project build for modules. We can add these modules to our workspace. Another workspace member such as frameworks can use other modules. The goal is to avoid code duplication and provide us to use code from other workspace modules.

22- Explain the Open/Closed Principle

This principle developed by Bertrand Meyer can be explained briefly as follows: It means developing the program and adding new behavior to the program. Programs according to OCP should be open to development. The modules that make up the program should be able to expand but should be closed to modification. If we follow the Open / Closed Principle, our class and interface will be more extendible.

23- What does agile process do?

The agile process only takes into account the needs specified by the customer, converted into a user story and prioritized by the customer. In short, the agile process does not think about the future.

24- Why is everything in a do-catch block?

In Swift, errors are thrown and handled inside of do-catch blocks. This allows us to customize our error handling and perform specific actions based on the error. With a do-catch statement, we can usetry. This allows us to check meaningful errors.

25- Why is the background mode important?

Because we can fetch data in the background with a background mode, allowing our app to show the latest information.

26- Explain the difference between print() and readLine()

We use print() statement for our standard outputs. It is followed by a default newline terminator. But sometimes we need standard inputs (StdIn) which read one line of user input. This means, we can readLine(). Also, readLine() returns an optional string when we call it.

27- Explain enumerated()

According to Apple, if we need the index for each element along with its value, you can use enumerated()method to iterate over the array.

28- Explain NSCache

NSCache is an NSDictionary that automatically clears itself out when our app receives a memory warning. NSCache is thread-safe.

29- Explain abs() function

You use the abs() function to calculate the positive difference between the one value to another value.

30- Explain TextKit

According to Apple, TextKit provides a number of classes to control the layout of text, such as NSTextStorage, NSLayoutManager, and NSTextContainer. Additionally, NSAttributedString objects are used extensively throughout TextKit.

I highly recommend watching TextKit Best Practices in WWDC 2018

31- What is the difference between try? and try! ?

try? allows us to ignore our error to become nil. We use try! it for our function to never encounter an error.

32- What is the difference between the cocoa touch class and the normal swift class?

If we choose Swift File, the next screen will show you file name and choose a save location. When we click “Create” from here, we simply get an empty(ish) Swift file with the name we picked. They do not provide different types of classes. They just provide different file templates.

33- Explain OptionSet

Option sets are similar to enums, but OptionSet designs to work more than one at a time. We can say enums are an exclusive state, OptionSet is an inclusive state. For creating an OptionSet, there is one requirement which is the rawValue the property of integer type, and an initializer. Option sets aren’t collections.

34- Explain the unified logging system

The unified logging system is a new logging mechanism as a replacement of print and NSLog is the recommended way of logging by Apple. The purpose of unified logging improves the privacy of our app. We use the os framework that we need for tracing activity and logging operations to make diagnosing problems in our app.

35- Explain Address Sanitizer

Address Sanitizer watches memory corruption and buffers overflows. It works for both the Simulator and on devices after a recompilation. We can also use compiler optimization level of None [-O0] or at most Fast [-O1].

We can enable it when running unit and UI tests.

36- Explain the Single Responsibility Principle

It is a software development principle that enables us to easily understand objects and object functions. It ranks first among the SOLID principles. According to this principle, it must be the only task of a method or class. If we speak for the method, the function loaded in a method should not be more than one.

37- Explain App thinning

App thinning is a combination of slicing, bit code, and on-demand resources (ODRs). This combination automatically detects the user’s device model and allows only relevant downloads for the specific device.

When the user finishes using resources, it purges from memory automatically.

38- What is the difference between setUp() and tearDown() in XCTestCase ?

We use these two methods for allocation. setUp method calls before test methods are executed. tearDown method calls after all test methods are executed for cleaning up any changes we made in data.

39- Explain Asset Catalogs

We use asset catalogs to store images such as icons or images. Since iOS 11, we can store named colors in asset catalogs. Another lesser-known feature of asset catalogs is that we can store arbitrary data assets. With iOS 13 now we can define dark mode icons and images.

40- Explain Dispatch Barriers

Dispatch barriers are a group of functions acting as a serial queue style objects. It creates asynchronous execution and helps us to make a thread-unsafe object thread-safe. Dispatch barriers guarantee no writing occurs while reading and no reading occurs while writing using concurrency.

41- What can breakpoint do?

42- Explain Opaque Return Types

I have a class that uses a protocol. It returns an error when I return this class with a function. Because the Swift compiler does not know what these classes are. Therefore, there is no problem when some is added to the return class, struct or protocol of the error function.

43- Explain Autoclosures

@autoclosure creates an automatic closure around the expression. When we write an expression, @autoclosure is automatically wrapped into a closure.

44- Explain UIScene Life Cycle

Unattached

The scene starts in the unattached state. If a request comes from a user, it goes to the foreground state. If a request comes from the system, it stays in the background.

Suspended

The scene does not do any work.

Background

The scene does not appear to the user. From the background, state can unattached, can suspend or can move to the foreground.

Foreground

The scene is presented to the user.

45- Explain Hashable type

You might want to check Part 3 — Q19 before reading the answer.

If we make that type Hashable such as a struct or an enum, we can pass our own objects. Because in Swift, Enums are automatically hashable. This will give a unique identifier. I highly recommend watching WWDC 2019 Advances in UI Data Sources session.

46- Explain Dynamic Var usage

I use KVO to trigger events on a case-by-case basis. Strong var variables cannot detect this trigger. This trigger can be detected when it puts dynamic at the beginning of the variable

47- Explain UIViewRepresentable requirements

The UIViewRepresentable protocol has two requirements we need to add: a makeUIView(context:) method and an updateUIView(_:context:) a method that configures the view and responds to any changes.

48- Explain Dynamic Member Lookup

DynamicMemberLookup attribute for type declarations. Child classes get access to their parent’s dynamic member lookup capabilities

49- Explain Result Type

The result type is implemented as an enum that has two cases: success and failure callbacks. Result has four other methods: map(), flatMap(), mapError(), and flatMapError(). Each of these gives you the ability to transform either success or error.

50- Explain Scene Delegate

With scene delegate, iOS applications can have more than one scene that allows us to build multi-window apps on iOS and iPadOS.

That’s it. 😃😃😃 Thanks for reading!

If you want to follow me on social media, here are some links: Github, Twitter, Instagram

You can check my previous articles here.

Health Research Program’s iOS Developer, currently lives in Washington, D.C http://www.about.me/durul

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store