Top iOS Interview Questions

iOS Interview Questions

Apple users are growing very rapidly around the world so the demand for iOS developers are increasing rapidly. so if you want to break into iOS development then you need to clear iOS interview. We have collected top interview questions from different sites, so that readers can read all here –

Q1. How can we setup Live Rendering ? 

in Xcode it is possible to change code at runtime and see the changes rendered live in the storyboard using IBDesignable. It is also possible to change user attributes live into the Interface Builder using IBInspectable.  So we need to use @IBDesignable keyword  to make view render live.

Q2. Difference between Synchronous & Asynchronous task ? 

When you invoke something synchronously, it means that the thread that initiated that operation will wait for the task to finish before continuing. Asynchronous means that it will not wait and works in background and will notify after completed.

swift 3, 4, 4,2 Synchronous means that thread that initiated that operation will wait for the task to finish before continuing.

1
2
DispatchQueue.main.sync {
}

Asynchronous means that Completes a task in background and can notify you when complete means it will not wait.

1
2
DispatchQueue.main.async {
}

Q3. Please explain B-Trees? 

A B-tree is a tree data structure that keeps data sorted and allows searches, insertions, and deletions in logarithmic amortized time. Unlike self-balancing binary search trees, it is optimized for systems that read and write large blocks of data. It is most commonly used in database and file systems.

Important properties of a B-tree:

  • B-tree nodes have many more than two children.
  • A B-tree node may contain more than just a single element.

Q4. What is made up of NSError object? 

Information about an error condition including a domain, a domain-specific error code, and application-specific information. An NSError object may also provide localized error descriptions suitable for display to the user in its user info dictionary. See Error Handling Programming Guide for more information.

1
class NSError : NSObject

Q5. Please explain about bounding box? 

Returns the bounding box containing all points in a graphics path. A rectangle that represents the bounding box of the specified path. If the path is empty, this function returns null. The bounding box is the smallest rectangle completely enclosing all points in the path, including control points for Bézier and quadratic curves.

var boundingBox: CGRect { get }

Q6. What are enums and why cant we use  strong for enum property in Objective-C? 

enum or enumeration is a data type that allows you to define a list of possible values. If you are a web developer then the easiest way to think of an enum is anywhere you would use a dropdown. A dropdown consists of a limited set of values from which you can choose one. An enum allows you to create a data type with those set of values so that they can be recognized consistently throughout your app.

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

Q7. What is @synthesize in Objective-C? 

You use the @synthesize keyword to tell the compiler that it should synthesize the setter and/or getter methods for the property if you do not supply them within the @implementation block. it creates a getter and a setter for the variable.

Q8. What is @dynamic in Objective-C? 

There are situations where you might want to provide an implementation of a method dynamically. For example, the Objective-C declared properties feature (see Declared Properties in The Objective-C Programming Language) includes the @dynamic directive:

1
@dynamic propertyName;

which tells the compiler that the methods associated with the property will be provided dynamically.

You can implement the methods

1
resolveInstanceMethod:

 and 

1
resolveClassMethod:

 to dynamically provide an implementation for a given selector for an instance and class method respectively.

Q9. What is Dynamic Typing

A variable is dynamically typed when the type of the object it points to is not checked at compile time. Objective-C uses the id data type to represent a variable that is an object without specifying what sort of object it is. This is referred to as dynamic typing.

Dynamic typing contrasts with static typing, in which the system explicitly identifies the class to which an object belongs at compile time. Static type checking at compile time may ensure stricter data integrity, but in exchange for that integrity, dynamic typing gives your program much greater flexibility. And through object introspection (for example, asking a dynamically typed, anonymous object what its class is), you can still verify the type of an object at runtime and thus validate its suitability for a particular operation.

Q10. What is Dynamic Binding 

methods are resolved dynamically at runtime. The exact code executed is determined by both the method name (the selector) and the receiving object.

Dynamic binding enables polymorphism. For example, consider a collection of objects including 

1
Dog

1
Athlete

, and 

1
ComputerSimulation

. Each object has its own implementation of a run method. In the following code fragment, the actual code that should be executed by the expression 

1
[anObject run]

 is determined at runtime. The runtime system uses the selector for the method run to identify the appropriate method in whatever the class of  anObject turns out to be.

Q.11 Why do we use synchronized? 

The presence of multiple threads in an application opens up potential issues regarding safe access to resources from multiple threads of execution. Two threads modifying the same resource might interfere with each other in unintended ways. For example, one thread might overwrite another’s changes or put the application into an unknown and potentially invalid state.

The @synchronized directive is a convenient way to create mutex locks on the fly in Objective-C code. The @synchronized directive does what any other mutex lock would do—it prevents different threads from acquiring the same lock at the same time.

Q12.  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.

Q13. What’s Code Coverage? 

Code coverage is a feature in Xcode 7 that enables you to visualize and measure how much of your code is being exercised by tests. With code coverage, you can determine whether your tests are doing the job you intended.

Q14. 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.

The completion handlers have to marked @escaping since they are executed some point after the enclosing function has been executed.

Q15. 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.

Q16. 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).

  • Important for: placing the view’s content or subviews within itself

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.

  • Important for: placing the view in the parent

Q17. What is Responder Chain ? 

The responder chain is a series of linked responder objects. It starts with the first responder and end with the app object. If the first responder cannot handle an event, it forwards the event to the next responder in the responder chain.

Apps receive and handle events using responder objects. A responder object is any instance of the 

1
UIResponder

 class, and common subclasses include 

1
UIView

1
UIView<wbr />Controller

, and 

1
UIApplication

. Responders receive the raw event data and must either handle the event or forward it to another responder object. When your app receives an event, UIKit automatically directs that event to the most appropriate responder object, known as the first responder.

Q18. What is Regular expressions ? 

Regular expressions are special strings that are used to search or validate strings.

Q19. What is Operator Overloading ? 

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

Q20. Can we use Operator Overloading in objective -c?

Operator overloading is not a feature of Objective-C. If two instances of your classes can be added together, provide a method and allow them to be added using that method:
Thing*result = [thingOne thingByAddingThing:thingTwo];

Or, if your class is mutable:

1
2
<span class="pun">[</span><span class="pln">thingOne addThing</span><span class="pun">:</span><span class="pln">thingTwo</span><span class="pun">];
</span>

Q21. What are different 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).

Q22. What is generics in swift?

Generic code enables you to write flexible, reusable functions and types that can work with any type, subject to requirements that you define. You can write code that avoids duplication and expresses its intent in a clear, abstracted manner.

Generics are one of the most powerful features of Swift, and much of the Swift standard library is built with generic code. In fact, you’ve been using generics throughout the Language Guide, even if you didn’t realize it. For example, Swift’s 

1
Array

 and 

1
Dictionary

types are both generic collections. You can create an array that holds 

1
Int

 values, or an array that holds 

1
String

 values, or indeed an array for any other type that can be created in Swift. Similarly, you can create a dictionary to store values of any specified type, and there are no limitations on what that type can be.

Q23. What is lazy in Swift ? 

lazy stored property is a property whose initial value is not calculated until the first time it is used. You indicate a lazy stored property by writing the 

1
lazy

 modifier before its declaration.

NOTE

You must always declare a lazy property as a variable (with the 

1
var

 keyword), because its initial value might not be retrieved until after instance initialization completes. Constant properties must always have a value before initialization completes, and therefore cannot be declared as lazy.

Lazy properties are useful when the initial value for a property is dependent on outside factors whose values are not known until after an instance’s initialization is complete. Lazy properties are also useful when the initial value for a property requires complex or computationally expensive setup that should not be performed unless or until it is needed.

Q24. what is defer ? 

1
defer

 statement is used for executing code just before transferring program control outside of the scope that the 

1
defer

 statement appears in.

1
defer

 statement has the following form:

1
2
3
defer {
statements
}

The statements within the defer  statement are executed no matter how program control is transferred. This means that a defer statement can be used, for example, to perform manual resource management such as closing file descriptors, and to perform actions that need to happen even if an error is thrown.

If multiple 

1
defer

 statements appear in the same scope, the order they appear is the reverse of the order they are executed. Executing the last 

1
defer

 statement in a given scope first means that statements inside that last 

1
defer

 statement can refer to resources that will be cleaned up by other 

1
defer

 statements.

1
2
3
4
5
6
7
8
9
func f() {
defer { print("First defer") }
defer { print("Second defer") }
print("End of function")
}
f()
// Prints "End of function"
// Prints "Second defer"
// Prints "First defer"

The statements in the 

1
defer

 statement can’t transfer program control outside of the 

1
defer

statement.

Q25. What is Compiler Control Statements in swift?
Compiler control statements allow the program to change aspects of the compiler’s behavior. Swift has three compiler control statements: a conditional compilation block a line control statement, and a compile-time diagnostic statement.
compiler-control-statement → conditional-compilation-block
compiler-control-statement → line-control-statement
compiler-control-statement → diagnostic-statement

Q26. What is NSApplicationMain attribute in Swift?
Apply this attribute to a class to indicate that it’s the application delegate. Using this attribute is equivalent to calling the NSApplicationMain(_:_:) function.

If you don’t use this attribute, supply a main.swift file with code at the top level that calls the NSApplicationMain(_:_:) function as follows:

1
2
import AppKit
NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)

Q27. Please explain Swift’s pattern matching techniques

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

Q28. What is guard statement and its benefits in Swift?
A guard statement is used to transfer program control out of a scope if one or more conditions aren’t met.
A guard statement has the following form:

1
2
3
guard condition else {
statements
}

The value of any condition in a guard statement must be of type Bool or a type bridged to Bool. The condition can also be an optional binding declaration, as discussed in Optional Binding.

Any constants or variables assigned a value from an optional binding declaration in a guard statement condition can be used for the rest of the guard statement’s enclosing scope.
There are 2 major benifits of using guard statement –
1. It helps to avoid pyramid of doom.
2. it provides an early out from a nested function like break and exit.

Q30. Which method is called first when app start?

1
application:willFinishLaunchingWithOptions:

—This method is your app’s first chance to execute code at launch time.

Q31. Which JSON framework is supported by iOS?
1. SBJson framework is supported by iOS. It is a JSON parser and generator for Objective-C (Objective-C is the primary programming language you use when writing software for OS X and iOS. It’s a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime).
2. SBJson provides flexible APIs and additional control that makes JSON handling easy.

Q32. Please explain difference between app ID and bundle ID.

An App ID is a two-part string used to identify one or more apps from a single development team. The string consists of a Team ID and a bundle ID search string, with a period (

1
.

) separating the two parts. The Team ID is supplied by Apple and is unique to a specific development team, while the bundle ID search string is supplied by you to match either the bundle ID of a single app or a set of bundle IDs for a group of your apps.
There are two types of App IDs: an explicit App ID, used for a single app, and wildcard App IDs, used for a set of apps.

An Explicit App ID Matches a Single App

For an explicit App ID to match an app, the Team ID in the App ID must equal the Team ID associated with the app, and the bundle ID search string must equal the bundle ID for the app. The bundle ID is a unique identifier that identifies a single app and cannot be used by other teams.

Wildcard App IDs Match Multiple Apps

A wildcard App ID contains an asterisk as the last part of its bundle ID search string. The asterisk replaces some or all of the bundle ID in the search string.
The asterisk is treated as a wildcard when matching the bundle ID search string with bundle IDs. For a wildcard App ID to match a set of apps, the bundle ID must exactly match all of the characters preceding the asterisk in the bundle ID search string. The asterisk matches all remaining characters in the bundle ID. The asterisk must match at least one character in the bundle ID.

The bundle ID defines each App and is specified in Xcode. A single Xcode project can have multiple targets and therefore output multiple apps. A common use case is an app that has both lite/free and pro/full versions or is branded multiple ways.

Q33. What are the ways of achieving concurrency in iOS?

    1. Threads
    2. Dispatch Queues
    3. Dispatch Sources
    4. Operation Queues

Q34.What is autorealease pool?
An autorelease pool stores objects that are sent a release message when the pool itself is drained.
Important

If you use Automatic Reference Counting (ARC), you cannot use autorelease pools directly. Instead, you use @autoreleasepool blocks. For example, in place of:

1
2
3
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Code benefitting from a local autorelease pool.
[pool release];

you would write:

1
2
3
@autoreleasepool {
// Code benefitting from a local autorelease pool.
}

@autoreleasepool blocks are more efficient than using an instance of NSAutoreleasePool directly; you can also use them even if you do not use ARC.
In a garbage-collected environment, there is no need for autorelease pools. You may, however, write a framework that is designed to work in both a garbage-collected and reference-counted environment. In this case, you can use autorelease pools to hint to the collector that collection may be appropriate.
In a garbage-collected environment, sending a drain message to a pool triggers garbage collection if necessary; release, however, is a no-op. In a reference-counted environment, drain has the same effect as release. Typically, therefore, you should use drain instead of release.

Q35. What is the difference between ‘assign’ and ‘retain’ keyword.
Retain -specifies that retain should be invoked on the object upon assignment. It takes ownership of an object.
Assign – specifies that the setter uses simple assignment. It is used on attribute of scalar type like float,int.

Reference Sites –

Leave a Reply

Your email address will not be published. Required fields are marked *


CAPTCHA Image
Reload Image