Ios Interview Questions

What is a memory leak?

A memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in such a way that memory which is no longer needed is not released. In object-oriented programming, a memory leak may happen when an object is stored in memory but cannot be accessed by the running code.

Describe what “app thinning” means ?

The store and operating system optimize the installation of iOS, tvOS, and watchOS apps by tailoring app delivery to the capabilities of the user’s particular device, with minimal footprint. This optimization, called app thinning, lets you create apps that use the most device features, occupy minimum disk space, and accommodate future updates that can be applied by Apple.

What is auto-layout?

Auto Layout dynamically calculates the size and position of all the views in your view hierarchy, based on constraints placed on those views.

What is GCD? How is it used?

GCD is the most commonly used API to manage concurrent code and execute operations asynchronously at the Unix level of the system. GCD provides and manages queues of tasks. A good example is when an App fetch data from an API, this network call should be done in a background thread and the display of the data in the view should be executed in the main thread as well as any UI updates.

What are the benefits of Swift over Objective-C ?

  • Swift is easier to read. (mmm really?)
  • Swift is easier to maintain.
  • Swift is safer.
  • Swift is unified with memory management.
  • Swift requires less code.
  • Swift is faster.
  • Fewer name collisions with open source projects.
  • Swift support dynamic libraries.
  • Swift Playgrounds encourages interactive coding.
  • Swift is a future you can influence.

What is Synchronous vs. Asynchronous in GCD ?

These terms describe when a function will return control to the caller, and how much work will have been done by that point.A synchronous function returns only after the completion of a task that it orders.

An asynchronous function, on the other hand, returns immediately, ordering the task to be done but not waiting for it. Thus, an asynchronous function does not block the current thread of execution from proceeding on to the next function.

Why do you generally create a weak reference when using self in a block?

To avoid retain cycles and memory leaks.

What is the GCD method you call to pass some work to a queue asynchronously? What parameters do you provide to this method?

dispatch_async(dispatch_get_main_queue(), ^{ });

We pass as a parameter the dispatch queue where we want to execute the code.

What are some ways to support newer API methods or classes while maintaining backward compatibility?

For instance, if you want your view to have a red tintColor (a method introduced in iOS 7), but your app still supports iOS 6, how could you make sure it won’t crash when running on iOS 6? Another example would be using NSURLSession vs. NSURLConnection — how could you make it so that your code uses the most appropriate of those two classes?

  • Treat deprecated APIs warnings as errors to resolve.
  • At runtime, check for OS versions.
  • objC : Mark legacy code paths with macros.

if #available(iOS 8, *, *) {

self.view.convertPoint(.Zero, toCoordinateSpace:anotherView)

} else {

self.view.convertPoint(CGPointZero, toView:anotherView)

}

  • Control the number of 3d party libraries.

What is MVC ?

MVC is a design pattern that stands for model view controller, this design pattern separates the data from its display, mediated by a View Controller.

What are delegates ?

Delegates are a design pattern. A delegate is just an object that another object sends messages to when certain things happen so that the delegate can handle app-specific details the original object wasn’t designed for. It’s a way of customizing behavior without subclassing. And it’s important to remember that they have one to one relationship.

What are NSNotificationCenter and how does it work ?

NSNotificationCenter is what Apple has provided as an Observer Pattern in the Cocoa library . The basic idea is that a listener registers with a broadcaster using some predefined protocol. At some later point, the broadcaster is told to notify all of its listeners, where it calls some function on each of its listeners and passes certain arguments along. This allows for asynchronous message passing between two different objects that don’t have to know about one another, they just have to know about the broadcaster.

What is Core Data ?

Core Data is not an ORM or object-relational mapper. Nor is it a database. Instead, Core Data is an object graph manager which also has the ability to persist object graphs to a persistent store, on a disk.

What is a managed object context ?

A managed object context represents a single object space, or scratch pad, in a Core Data application.

Difference between frame and bounds ?

The bounds of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).

The frame of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.

What is the purpose of the reuseIdentifier ?

Reusability of an already allocated object.

How many UITableViewCells are allocated when you first load a UITableView? How many additional ones are allocated as you scroll through the table?

A UITableView will normally allocate just enough UITableViewCell objects to display the content visible in the table. Because of the reuseIdentifier , the UITableView will not allocate new UITableViewCell objects for each new item that scrolls into view, avoiding laggy animations.

Define atomic and nonatomic.

  • Atomic is the default: if you don’t type anything, your property is atomic. An atomic property is guaranteed that if you try to read from it, you will get back a valid value. It does not make any guarantees about what that value might be, but you will get back good data, not just junk memory. What this allows you to do is if you have multiple threads or multiple processes pointing at a single variable, one thread can read and another thread can write. If they hit at the same time, the reader thread is guaranteed to get one of the two values: either before the change or after the change. What atomic does not give you is any sort of guarantee about which of those values you might get. Atomic is reallycommonly confused with being thread-safe, and that is not correct. You need to guarantee your thread safety other ways. However, atomic will guarantee that if you try to read, you get back some kind of value.
  • On the flip side, non-atomic, as you can probably guess, just means, “don’t do thatatomic ” What you lose is that guarantee that you always get back something. If you try to read in the middle of a write, you could get back garbage data. But, on the other hand, you go a little bit faster. Because atomic properties have to do some magic to guarantee that you will get back a value, they are a bit slower. If it is a property that you are accessing a lot, you may want to drop down to nonatomic to make sure that you are not incurring that speed penalty.

Whats the difference between weak and strong ?

These keywords are related to reference counting and “denote ownership”, if you will. They help you eliminate retain-release cycles by limiting what objects increment the reference count for another object. A strong property is one where you increment the reference count of the object. If object A has a strong reference to B, and no other object is referencing B, B has count 1 (A owns, or needs to exist B). Now, if B wants to have a reference to A, we would want to use a weak reference. Weak references don’t increment the reference count of the object. So in this particular case, if A has no other objects referencing it but B, A’s count would be 0 given B’s weak reference.

What’s the difference between not-running, inactive, active, background and suspended execution states?

  • Not running:The app has not been launched or was running but was terminated by the system.
  • Inactive:The app is running in the foreground but is currently not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state.
  • Active:The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.
  • Background:The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state.
  • Suspended:The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code. When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.

What is a category and when is it used ?

A category is a way of adding additional methods to a class without extending it. It is often used to add a collection of related methods. A common use case is to add additional methods to built-in classes in the Cocoa frameworks.

What is the difference between viewDidLoad and viewDidAppear? Which should you use to load data from a remote server to display in the view?

viewDidLoad is called when the view is loaded, whether from a Xib file, storyboard or pro grammatically created in load View. viewDidAppear is called every time the view is presented on the device. Which to use depends on the use case for your data. If the data is fairly static and not likely to change then it can be loaded in viewDidLoad and cached. However, if the data changes regularly then using viewDidAppear to load it is better. In both situations, the data should be loaded asynchronously on a background thread to avoid blocking the UI.

What’s the difference between using a delegate and notification?

Both are used for sending values and messages to interested parties. A delegate is for one-to-one communication and is a pattern promoted by Apple. In delegation, the class raising events will have a property for the delegate and will typically expect it to implement some protocol. The delegating class can then call the delegates protocol methods.

Notification allows a class to broadcast events across the entire application to any interested parties. The broadcasting class doesn’t need to know anything about the listeners for this event, therefore notification is very useful in helping to decouple components in an application.

What happens when you invoke a method on a nil pointer ?

A message sent to a nil object is perfectly acceptable in Objective-C, it’s treated as a no-op. There is no way to flag it as an error because it’s not an error, in fact, it can be a very useful feature of the language.

Which is faster: to iterate through an NSArray or an NSSet?

When the order of the items in the collection is not important, NSSet offers better performance for finding items in the collection; the reason is that the NSSet uses hash values to find items (like a dictionary), while an array has to iterate over its entire contents to find a particular object.

What is Decorator Design Pattern ?

The Decorator pattern dynamically adds behaviors and responsibilities to an object without modifying its code. It’s an alternative to subclassing where you modify a class’s behavior by wrapping it with another object.

What is the difference between Synchronous & Asynchronous task ?

Synchronous: waits until the task has completed Asynchronous: completes a task in background and can notify you when complete

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.

What is made up of NSError object?

There are three parts of NSError object a domain, an error code, and a user info dictionary. The domain is a string that identifies what categories of errors this error is coming from.

What is bounding box?

Bounding box is a term used in geometry; it refers to the smallest measure (area or volume) within which a given set of points.

Why don’t we use strong for enum property in Objective-C ?

Because enums aren’t objects, so we don’t specify strong or weak here.

What is synthesize in Objective-C ?

synthesize generates getter and setter methods for your property.

What is dynamic in Objective-C ?

We use dynamic for subclasses of NSManagedObject. @dynamic also can be used to delegate the responsibility of implementing the accessors.

Why do we use synchronized ?

synchronized guarantees that only one thread can be executing that code in the block at any given time.

What is the difference strong, weaks, read only and copy ?

Strong means that the reference count will be increased and
the reference to it will be maintained through the life of the object

Weak, means that we are pointing to an object but not increasing its reference count. It’s often used when creating a parent child relationship. The parent has a strong reference to the child but the child only has a weak reference to the parent.

Read only, we can set the property initially but then it can’t be changed.

Copy, means that we’re copying the value of the object when it’s created. Also prevents its value from changing.

What is Dynamic Dispatch ?

Dynamic Dispatch is the process of selecting which implementation
of a polymorphic operation that’s a method or a function to call at run time. This means, that when we wanna invoke our methods like object method. but Swift does not default to dynamic dispatch

What’s Code Coverage ?

Code coverage is a tool that helps us to measure the value of our unit tests.

What’s Completion Handler ?

Completion handlers are super convenient when our app is making an API call, and we need to do something when that task is done, like updating the UI to show the data from the API call. We’ll see completion handlers in Apple’s APIs like dataTaskWithRequest and they can be pretty handy in your own code.

The completion handler takes a chunk of code with 3 arguments:(NSData?, NSURLResponse?, NSError?) that returns nothing: Void. It’s a closure.

How to Prioritize Usability in Design ?

Broke down its design process to prioritize usability in 4 steps:

  • Think like the user, then design the UX.
  • Remember that users are people, not demographics.
  • When promoting an app, consider all the situations in which it could be useful.
  • Keep working on the utility of the app even after launch.

What’s the difference between the frame and the bounds?

The bounds of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).
The frame of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.

What’s What is Responder Chain ?

A ResponderChain is a hierarchy of objects that have the opportunity to respond to events received.

What is Regular expressions ?

Regular expressions are special string patterns that describe how to search through a string.

What is Operator Overloading ?

Operator overloading allows us to change how existing operators behave with types that both already exist.

What is TVMLKit ?

TVMLKit is the glue between TVML, JavaScript, and your native tvOS application.

What is Platform limitations of tvOS ?

First, tvOS provides no browser support of any kind, nor is there any WebKit or other web-based rendering engine you can program against. This means your 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 on-board storage.

tvOS app bundle cannot exceed 4 GB.

What is Functions ?

Functions let us group a series of statements together to perform some task. Once a function is created, it can be reused over and over in your code. If you find yourself repeating statements in your code, then a function may be the answer to avoid that repetition.

What is ABI ?

ABIs are important when it comes to applications that use external libraries. If a program is built to use a particular library and that library is later updated, you don’t want to have to re-compile that application (and from the end-user’s standpoint, you may not have the source). If the updated library uses the same ABI, then your program will not need to change.

Why is design pattern very important ?

Design patterns are reusable solutions to common problems in software design. They’re templates designed to help you write code that’s easy to understand and reuse. Most common Cocoa design patterns:

  • Creational: Singleton.
  • Structural: MVC, Decorator, Adapter, Facade.
  • Behavioral: Observer, and, Memento

What is Singleton Pattern ?

The Singleton design pattern ensures that only one instance exists for a given class and that there’s a global access point to that instance. It usually uses lazy loading to create the single instance when it’s needed the first time.

What is Facade Design Pattern ?

The Facade design pattern provides a single interface to a complex subsystem. Instead of exposing the user to a set of classes and their APIs, you only expose one simple unified API.

Why don’t we use strong for enum property in Objective-C ?

Because enums aren’t objects, so we don’t specify strong or weak here.

Explain MVVM ?

UIKit independent representation of your View and its state. The View Model invokes changes in the Model and updates itself with the updated Model, and since we have a binding between the View and the View Model, the first is updated accordingly.

Your view model will actually take in your model, and it can format the information that’s going to be displayed on your view.

How many different annotations available in Objective-C ?

  • Null_unspecified, which bridges to a Swift implicitly unwrapped optional. This is the default.
  • Nonnull, the value won’t be nil it bridges to a regular reference.
  • Nullable the value can be nil, it bridges to an optional.
  • Null_resettable the value can never be nil, when read but you can set it to know to reset it. This is only apply property.

What is JSON/PLIST limits ?

  • We create your objects and then serialized them to disk..
  • It’s great and very limited use cases.
  • We can’t obviously use complex queries to filter your results.
  • It’s very slow.
  • Each time we need something, we need to either serialize or deserialize it.
  • it’s not thread-safe.

What is SQLite limits ?

  • We need to define the relations between the tables. Define the schema of all the tables.
  • We have to manually write queries to fetch data.
  • We need to query results and then map those to models.
  • Queries are very fast.

What is Realm benefits ?

  • An open-source database framework.
  • Implemented from scratch.
  • Zero copy object store.
  • Fast.

How many are there APIs for battery-efficient location tracking ?

There are 3 apis.

  • Significant location changes — the location is delivered approximately every 500 metres (usually up to 1 km)
  • Region monitoring — track enter/exit events from circular regions with a radius equal to 100m or more. Region monitoring is the most precise API after GPS.
  • Visit events — monitor place Visit events which are enters/exits from a place (home/office).

What is the Swift main advantage ?

To mention some of the main advantages of Swift:

  • Optional Types, which make applications crash-resistant
  • Built-in error handling
  • Closures
  • Much faster compared to other languages
  • Type-safe language
  • Supports pattern matching

Explain generics in Swift ?

Generics create code that does not get specific about underlying data types.

Explain lazy in Swift ?

An initial value of the lazy stored properties is calculated only when the property is called for the first time. There are situations when the lazy properties come very handy to developers.

Explain what is defer ?

defer keyword which provides a block of code that will be executed in the case when execution is leaving the current scope.

How to pass a variable as a reference ?

We need to mention that there are two types of variables: reference and value types. The difference between these two types is that by passing value type, the variable will create a copy of its data, and the reference type variable will just point to the original data in the memory.

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.

What is Concurrency ?

Concurrency is dividing up the execution paths of your program so that they are possibly running at the same time. The common terminology: process, thread, multithreading, and others. Terminology;

  • Process, An instance of an executing app
  • Thread, Path of execution for code
  • Multithreading, Multiple threads or multiple paths of execution running at the same time.
  • Concurrency, Execute multiple tasks at the same time in a scalable manner.
  • Queues, Queues are lightweight data structures that manage objects in the order of First-in, First-out (FIFO).
  • Synchronous vs Asynchronous tasks

Grand Central Dispatch (GCD)?

GCD is a library that provides a low-level and object-based API to run tasks concurrently while managing threads behind the scenes. Terminology;

  • Dispatch Queues, A dispatch queue is responsible for executing a task in the first-in, first-out order.
  • Serial Dispatch Queue A serial dispatch queue runs tasks one at a time.
  • Concurrent Dispatch Queue A concurrent dispatch queue runs as many tasks as it can without waiting for the started tasks to finish.
  • Main Dispatch Queue A globally available serial queue that executes tasks on the application’s main thread.

Readers-Writers?

Multiple threads reading at the same time while there should be only one thread writing. The solution to the problem is a readers-writers lock which allows concurrent read-only access and an exclusive write access. Terminology;

  • Race Condition A race condition occurs when two or more threads can access shared data and they try to change it at the same time.
  • Deadlock A deadlock occurs when two or sometimes more tasks wait for the other to finish, and neither ever does.
  • Readers-Writers problem Multiple threads reading at the same time while there should be only one thread writing.
  • Readers-writer lock Such a lock allows concurrent read-only access to the shared resource while write operations require exclusive access.
  • Dispatch Barrier Block Dispatch barrier blocks create a serial-style bottleneck when working with concurrent queues.

NSOperation — NSOperationQueue — NSBlockOperation?

NSOperation adds a little extra overhead compared to GCD, but we can add dependency among various operations and re-use, cancel or suspend them.

NSOperationQueue, It allows a pool of threads to be created and used to execute NSOperations in parallel. Operation queues aren’t part of GCD.

NSBlockOperation allows you to create an NSOperation from one or more closures. NSBlockOperations can have multiple blocks, that run concurrently.

KVC — KVO?

KVC adds stands for Key-Value Coding. It’s a mechanism by which an object’s properties can be accessed using string’s at runtime rather than having to statically know the property names at development time.

KVO stands for Key-Value Observing and 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.

Please explain Swift’s pattern matching techniques?

  • Tuple patterns are used to match values of corresponding tuple types.
  • Type-casting patterns allow you to cast or match types.
  • Wildcard patterns match and ignore any kind and type of value.
  • Optional patterns are used to match optional values.
  • Enumeration case patterns match cases of existing enumeration types.
  • Expression patterns allow you to compare a given value against a given expression.

Please explain Swift’s pattern matching techniques?

There are two big benefits to guard. One is avoiding the pyramid of doom, as others have mentioned — lots of annoying if let statements nested inside each other moving further and further to the right. The other benefit is provide an early exit out of the function using break or using return.

Summary
Review Date
Reviewed Item
Thanks for sharing IOS Interview Questions and Answers, Very Helpful!!
Author Rating
51star1star1star1star1star