Interview Questions and Answers in iOS — Part 5

Interview questions and answers in iOS in very simple language.

Naveen Sharma
11 min readJun 2, 2020
Interview Questions and Answers in iOS

Q. What is Core Data?
A.
-
Core Data is not a relational database. Core Data is not an ORM or object-relational mapper. Nor it is a database.
- It is actually a framework that lets the developer store or retrieves data in the database in an object-oriented way.
- Core Data is an object graph manager that also has the ability to persist object graphs to a persistent store, on a disk.
- It provided by apple in the Mac OS X 10.4 Tiger and iOS 3.0.
- SQLite database is the default persistent store for core data on the iPhone.
- With Core Data, We can easily map the object in our apps to the table records in the database without even knowing any SQL.

Q. Object Graph?
A. An object graph is nothing more than a collection of objects(form a network) that are connected with one another.
The Core Data framework takes care of managing the life cycle of the objects in the object graph.
Object graphs may be small or large, simple or complex.

Q. Persistent Store types supported by core data?
A. NSSQLiteStoreType
NSXMLStoreType
NSBinaryStoreType
NSInMemoryStoreType

Q. Core Data Stack?
A. A Core Data stack is composed of the following objects: one or more managed object contexts connected to a single persistent store coordinator which is in turn connected to one or more persistent stores.
Apple’s Documentation

Core Data Stack Representation (Source: objc.io)

Q. NSManagedObjectModel or Managed Object Model?
A. The managed object model represents the data model (CoreDataDemo.xcdatamodeld) of the application. Even though Core Data isn’t a database, we can compare the managed object model to the schema of a database, that is, it contains information about the models or entities of the object graph, what attributes they have, and how they relate to one another.

Q. NSManagedObject or Managed Object (Entity)?
A. A managed object is a model object that represents a record from a persistent store. A managed object is an instance of NSManagedObject class or a subclass of NSManagedObject class. A managed object is registered with a managed object context.

Apple’s Documentation

Q. NSManagedObjectContext or Managed Object Context?
A.
-
Collection of Managed Object.
- A managed object context is an instance of NSManagedObjectContext. Its primary responsibility is to manage a collection of managed objects.
- The managed object context manages a collection of managed object, instances of the NSManagedObject class, and keeps a reference to a persistent store coordinator.
- It is possible for an application to have multiple managed object contexts. Each managed object context is backed by a persistent store coordinator.

- We can see a managed object context as a workbench on which we work with our managed object models. We load them, We manipulate them, and save them on that workbench. Loading and saving are mediated by the persistent store coordinator. We can have multiple workbenches, which is useful if our application is multithreaded, for example:
While a managed object model and persistent store coordinator can be shared across threads, managed object contexts should never be accessed from a thread different than the one they were created on.

Q. Persistent Store?
A. A persistent store is a repository in which managed objects may be stored. Core Data offers three native file types for a persistent store: binary, XML, and SQLite. We can implement our own store type if we want Core Data to interoperate with a custom file format or server. Core Data also provides an in-memory store that lasts no longer than the lifetime of a process.

Apple’s Documentations

Q. Persistent Object Store?
A. A persistent object store maps between objects in our application and records in a persistent store.

Q. Persistent Store Coordinator?
A.
-
A persistent store coordinator is an instance of NSPersistentStoreCoordinator.
- It has a reference to a managed object model that describes the entities in the store or stores it manages.
- It mediates between the persistent store(s) and the managed object context(s) and also takes care of loading, saving and caching data.

Single Persistent Stack (Source: Apple)
Visual Representation of All Above Points (Source: https://code.tutsplus.com/)

Q. NSBatchDeleteRequest?
A. A request to Core Data to do a batch delete of data in a persistent store without loading any data into memory. This is a much faster process because the delete is happening directly on the data store, which means no need for NSManagedObjectContext.

Q. NSBatchDeleteResult?
A. The result returned when executing a batch delete request.

Q. What is NSFetchRequest?
A. NSFetchRequest is the class responsible for fetching from Core Data. Fetch requests are both powerful and flexible. We can use fetch requests to fetch a set of objects meeting the provided criteria, individual values, and more.

Q. What is NSPersistentContainer?
A.
-
Introduced in iOS 10.0.
- A container that encapsulates the Core Data stack in your app.
- NSPersistentContainer simplifies the creation and management of the Core Data stack by handling the creation of the managed object model (NSManagedObjectModel), persistent store coordinator (NSPersistentStoreCoordinator), and the managed object context (NSManagedObjectContext).

Q. Explain NSFetchedResultsController?
A. NSFetchedResultsController is a controller, but it’s not a view controller. It has no user interface. Its purpose is to make developers’ lives easier by abstracting away much of the code needed to synchronize a table view with a data source backed by Core Data.

Q. Transformable Type in CoreData?
A. Core Data supports a variety of data types, for example, Int, Boolean, String, Float, Date, etc. In most cases this is sufficient, but sometimes we want to store data of a different type, for example, UIColor or UIImage. We can do this by creating a Transformable property. When we declare a property as Transformable Core Data converts our custom data type into binary Data when it is saved to the persistent store and converts it back to our custom data type when fetched from the store. It does this through a value transformer.

A ValueTransformer is simply a class that transforms a value into another one.

Notes:
- Relationships: To-One, To-Many, Many-To-Many, and Reflexive
- Delete Rules: No Action, Nullify, Cascade, and Deny

Links to Learn Core Data in Deep:
Apple
raywenderlich
objc.io
tutsplus

Q. Explain Bridging Headers in the iOS project?
A.
Bridging Headers allow us to include Objective-C files with our Swift files.

Q. Apple Id?
A. An automatically generated Id assigned to our app and unique to Apps.

Q. SKU?
A. SKU stands for Stock Keeping Unit. It should be alphanumeric and can not have spaces. It is a unique Id for our app that is not visible in the app store. Apple doesn’t do anything with this except display it on reports generated for our record keeping.

Q. Bundle Id?
A. A reverse domain name style string defined in Xcode and uniquely identifies an application bundle on a device.
It must be the same as AppId registered with Apple in order to deploy.

Q. Team ID?
A. A 10 character alphanumeric hash. Unique to every developer account.

Q. App ID?
A. The App ID string contains two parts separated by a period (.). An App Id prefix that is defined as our Team ID by default and App ID suffix that is defined as Bundle ID.

Explicit App Id com.companyname.projectname It can only be associated with a single App and compatible with all App Services.
WildCard App Id com.companyname.*. It contains asterisk at the place of the project name. It can be associated with multiple apps. Not compatible with Game Centre, In-App Purchase, or Push Notification App Service.

Q. Describe what “app thinning” means?
A.
-
The App Store and operating system optimize the installation of iOS, tvOS, and watchOS apps by tailoring app delivery as per the capabilities of the user’s particular device, with a minimal footprint. This optimization, called app thinning.
- There are three main aspects of App Thinning: App Slicing, Bitcode, and On-Demand Resources.
- Slicing is the process of creating different variations of the app bundle for different target devices.
- Bitcode is an intermediate representation of a compiled program. Including bitcode will allow Apple to re-optimize our app binary in the future without the need to submit a new version of our app to the store.
- On-demand resources are files that can be downloaded after the app’s first installation. For example, specific levels of a game (and these levels’ associated content) could be downloaded only when the player has unlocked them. Further, earlier levels that the player has not engaged with after a certain set time can be removed to save storage on the device.

Q. What is ‘Over The Air’ iOS App Release And Distribution?
A. Over the Air (OTA) is a method of wirelessly distributing an application and/or its updates to end-users.

Q. How would you securely store private user data offline on a device? What other security best practices should be taken??
A. There is no right answer to this. It totally depends on the Client and Application requirement. There are a few best practices, we need to keep in mind while developing an application:
- If the data is extremely sensitive then it should never be stored offline on the device because all devices are crackable.
- The keychain is one option for storing data securely. However, it’s encryption is based on the pin code of the device. Users are not forced to set a pin, so in some situations, the data may not even be encrypted. In addition, the user’s pin code may be easily hacked.
- A better solution is to use something like SQLCipher which is a fully encrypted SQLite database. The encryption key can be enforced by the application and separate from the user’s pin code.
- Only communicate with remote servers over SSL/HTTPS.
- If possible implement certificate pinning in the application to prevent man-in-the-middle attacks on public WiFi.
- Clear sensitive data out of memory by overwriting it.
- Ensure all validation of data being submitted is also run on the server-side.

Q. What is pair programming?
A. Pair programming is a way/process to share information with junior developers. Junior and senior developers sit side-by-side. This is the best way for the junior to learn from senior developers.
Check out Martin Fowler on “Pair Programming Misconceptions”, WikiHow on Pair Programming.

Q. What does Yak Shaving mean?
A. Yak shaving is a programming term that refers to a series of tasks that need to be performed before a project can progress to its next milestone.

Q. What is Webhooks?
A. Webhooks allow external services to be notified when certain events happen within our repository. (push, pull-request, fork).

Q. What is HealthKit?
A. HealthKit is an iOS framework. It stores health and fitness data in a central location. It takes data from multiple sources, which could be different devices. It allows users to control and access their data and maintains the privacy of user data. Data is synced between our phone and our watch.

Q. What is TVMLKit?
A. TVMLKit is the glue between TVML, JavaScript, and our native tvOS application.

Q. What is Platform limitations of tvOS?
A. First, tvOS provides no browser support of any kind, nor is there any WebKit or other web-based rendering engines we can program against. This means our app can’t link out to a web browser for anything, including web links, OAuth, or social media sites.

Second, tvOS apps cannot explicitly use local storage. At product launch, the devices ship with either 32 GB or 64 GB of hard drive space, but apps are not permitted to write directly to the onboard storage.

tvOS app bundle cannot exceed 4 GB.

Q. What is CoreSpotlight?
A. CoreSpotlight allows us to index any content inside of our app. While NSUserActivity is useful for saving the user’s history, with this API, we can index any data we like. It provides access to the CoreSpotlight index on the user’s device.

Q. What is Continuous Integration?
A. 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
Xcode Server
Jenkins
TeamCity

Cloud solutions
TravisCI
Bitrise
Buddybuild

Q. Are you using CharlesProxy? Why/why not?
A. If I need a proxy server that includes both complete requests and responses and the HTTP headers then I am using CharlesProxy. With CharlesProxy, we can support binary protocols, rewriting, and traffic throttling.

Q. How do you follow up on clean code for your project?
A. I follow the style guide and coding conventions for Swift projects of Github and SwiftLint.

Q. What is Instruments in Xcode?
A. Xcode Instruments are a powerful performance tuning tool to analyze the performance, memory footprint, smooth animation, energy usage, leaks, and file/network activity.

Q. What kind of benefits does the Xcode server have for developers?
A. Xcode server automatically checks out our project, build the app, run tests, and archive the app for distribution.

Q. What is Xcode Bot?
A. Xcode Server uses bots to automatically build our projects. A bot represents a single remote repository, project, and scheme. We can also control the build configuration the bot uses and choose which devices and simulators the bot will use.

Q. Can we install an iOS app on a real device without a paid developer account?
A. YES, we can. But, without enrolling in the Apple Developer Program, Our app will only last for 7 days on our device. After that, we’ll have to re-deploy it to our device via Xcode. If we’re enrolled in the Apple Developer Program, we won’t have this inconvenience.
But we do still need a paid Apple Developer account if we want to distribute our app in the App Store.

Q. What is the difference between LLVM and Clang?
A. Clang is the front end of the LLVM toolchain ( “clang” C Language Family Frontend for LLVM ). Every Compiler has three parts.
1. Front end ( lexical analysis, parsing )
2. Optimizer ( Optimizing abstract syntax tree )
3. Back end ( machine code generation )

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

Q. What is LLDB?
A.
It’s the debugger of The LLVM Compiler Infrastructure. Here is the homepage and this is a good article about it: Dancing in the Debugger — A Waltz with LLDB.

Q. Where do we use Dependency Injection?
A. We use a storyboard or xib in our iOS app, then we create 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.

Q. What Is Dependency Management?
A. 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. More Details

Q. Explain the difference between dependency injection and inject dependencies?
A.
Using dependency injection for a view model or view controller is easy enough, but to inject dependencies into every view on-screen would be significant work and a lot more lines of code to manage.

Q. What is circular dependencies?
A.
A circular dependency is a relation between two or more modules that either directly or indirectly depend on each other to function properly. Such modules are also known as mutually recursive.

Q. Tools to manage dependencies in iOS development?
A. CocoaPods, Carthage, Swift Package Manager

Thank you for reading! If you liked this article, please clap to get this article seen by more people.
Please follow me on Medium by clicking Follow.
I’m also active on LinkedIn, Twitter, and GitHub.

--

--