iOS Interview Questions

It’s time to land your dream job. If you are planning to build a career as an iOS Developer, prepare in advance with these frequently asked iOS interview questions. These iOS Developer interview questions have been answered by the top industry experts and have been proven to be helpful. Interview questions for ios Developer here will boost your knowledge and confidence in a short period of time. With these basic ios interview questions, you will be able to answers questions like What happens when the app receives a push notification?’, ‘Ways to Modify below code using Dependency Injection’, ‘What is the difference between the consumable and non-consumable type of in-app purchase?’. Be prepared and chase your dream job.

  • 4.7 Rating
  • 13 Question(s)
  • 15 Mins of Read
  • 9243 Reader(s)

Intermediate

35

Higher order functions are simply functions that can either accept functions or closures as arguments or return a function/closure.

Higher Order Functions are very useful and powerful and help us to write more elegantly and maintainable code. Those functions are Map, Filter, Reduce, Sort, CompactMap etc.

let result = [listOne.compactMap({ $0}),listTwo.compactMap({ $0})].flatMap({ $0}).reduce(0) { $0 + $1 }

First compact map removes nil element from the array. Then by using a flat map, we combine these two arrays.

And finally, reduce function will help to get the sum of array elements.

NO - They are similar but have a slightly different purpose.

Swift document says, “If you assign a closure to a property of a class instance, and the closure captures that instance by referring to the instance or its members, you will create a strong reference cycle between the closure and the instance.”

See below example.

class Device {
   var closure: (() -> ())?
   var name = "iPad"
   init() {
       self.closure = {
           print("inventory has \(self.name)")
       }
   }
}
var iPad:Device? = Device()
iPad?.closure?()
iPad = nil

Here device instance iPad will never be released due to a strong reference cycle as described.

So we have to use a capture list. Capture lists help us avoid memory problems. Inside the capture list, we can use weak or unowned to avoid any strong reference.

weak: use weak when the captured value may become nil.

class Device {
   var closure: (() -> ())?
   var name = "iPad"
   init() {
       self.closure = {[weak self] in
           print("inventory has \(self?.name)")
       }
   }
}
var iPad:Device?
iPad = Device()
iPad?.closure?()
iPad = nil

unowned: If we know for sure captured value will never become nil while the closure is called. In the below code, We are creating a non-nil instance of the device. So will sure that name will be always available.

class Device {
   var closure: (() -> ())?
   var name = "iPad"
   init() {
       self.closure = {[unowned self] in
           print("inventory has \(self.name)")
       }
   }
}
var iPad = Device()
iPad.closure?()

As iOS developers we know, Bundle ID is a string that uniquely identifies an application in the app store. So while developing the app we have to choose unique bundle-id for our app. Apple recommends reverse domain name for this, like com.yourCompany.yourApp

For the above scenario. As apple guidelines say, once your application successfully uploaded to store, you can’t change the bundle ID later.  So always make sure that you choose a bundle identifier that makes sense for the project and the owner.

With URLSession APIs availability, Now it becomes easier to build up network requests. The developer can build own networking layer on top of URLSession.

Alamofire is popular Elegant HTTP Networking library in Swift. Alamofire saves you a ton of time and simplifies the use. It is a well-tested library. Maintained by very clever people. Cost of including it - very small.

For small projects and projects with less time-line Alamofire is a good choice.

But for long term product, we can build in the house layer with NSURLSession. To avoid third-party dependency and upgrade overhead.

Apple provides great security mechanisms like Keychain, data encryption, or App Transport Security(which forces developers to use SSL pinning).

Keychain is the password management system developed by Apple. Logins, keys, and passwords should be stored in Keychain.

For network request, SSL pinning is used to ensure that an application communicates with the right server. For this, we need to save the SSL certificate within the app bundle.

Others security mechanisms are like using encryption methods like  AES-256 encryption while saving sensitive data to persistent storage or passing data over the internet.

OUTPUT:

Albert Einstein got 80.0 marks in this exam

80.0 for Albert Einstein in this exam

Here we have defines two classes, Student and ScoreCard. Each student owns one scoreCard also Each scoreCard belongs to the specific student.

Finally, we have created a student with the name  "Albert Einstein" and ScoreCard with 80 marks. We assigned scorecard to student and student to scorecard. Now both objects are strongly referencing to each other. So they will never be removed from memory. This code will cause a memory leak.

To fix this, we have to use weak reference for scoreCard property of student class.

class Student {
   let name: String
   init(name: String) {
       self.name = name
   }
   weak var scoreCard: ScoreCard?{
       didSet{
           print("\(name) got \(scoreCard!.marks) marks in this exam")
       }
   }
}

When the user receives a notification, there are two possible outcome actions depending on the app state.

  1. The app is not running and user taps on push notification, then didFinishLaunching method get called but with notification info in launchOption parameter.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   //Check if the app is trigger up by the Push notification
   if ([launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
       NSDictionary* notificationInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
       }
}
  1. The app is running (in foreground or background), then below method get called
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
}

Consumable: Customer needs to buy consumable in-app purchase items every time for the following cases,

  • If he deletes the old app and installs again.
  • In case of a change in device. It’s used for,
  • Game currency
  • Game Hints
  • Extra health
  • Extra experience points
  • A package of exports to a new file format etc.

Non-consumable: This type is commonly used in-app purchase. It's like a one-time purchase. Customer can use that feature with multiple devices using his Apple ID. Even if you delete and re-install application you can still restore your purchase features. It’s used for:

  • Upgrade to pro edition
  • Remove Ads
  • Full game unlock
  • Unlimited hints
  • Extra characters
  • Extra accessories
  • Bonus game levels
  • City guide maps

First, it will print “Apple”.

Next logic is contained in a 'main' async event. So it's postponed. The next thing it will print is "Apple TV".

Once the main thread is free, our first main.async task will run. So “iPod” will print.

Next to its main.async task again. For this to execute, the main thread needs free. Since we're still in the middle of the control flow, It will move to DispatchQueue.global().sync.

Read carefully, that it's dispatching sync not async. That means that the main thread is frozen until the code dispatched to the global queue is done.

Then it will print “Apple Watch”.

So finally prints “iPhone”.

Step 1:   Check if the user reaches the end of the list, then update page number by One.

Fetch your API with new page number until the last page.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

   if indexPath.row == list.count - 1 {
       self.fetchMoreItems(currentPageNumber)
   }
}

Step 2: Implement self.fetchMoreItems()

func fetchMoreItems(_ pageNumber:Int) {
   guard pageNumber < totalPageCount else {
       return
   }
   pageNumber = pageNumber + 1
   //Call get data API with updated page number{
       // Parse Response
           // Reload Table
   }
}

Swift is static: The compiler must have all information about all classes and functions at compile time. You can "extend" an existing class (with an extension), but even then you must define completely at compile time what that extension consists of.


Objective-C is dynamic: Objective-C was extremely influenced by Smalltalk, which had demonstrated the benefits of duck typing. This is also known as late binding, runtime binding, or the late dispatch. It’s dynamic because the responder of a message isn’t baked in at compile time, but is deferred until the actual point of sending the message.

Dependency injection is a technique/pattern help to adopt loose coupling between related objects. It also helps in unit testing.

The above example demonstrates one of the types of Dependency Injection, property injections.  Here we are injecting Network manager instance when it required.

class LogInViewController: UIViewController {
   var networkManager : NetworkManager?
}
func loginAction(){
   let loginVC = myStoryboard.instantiateViewController(withIdentifier: "LogInViewController") as! LogInViewController
   loginVC.networkManager = NetworkManager()
   loginVC.networkManager.doSomeAction()
}

Add GPS locations in GPX file and add GPX this file to your project. You can go to http://gpx-poi.com/ and simply fill the required data.
Just go to Target → Edit scheme and select GPX file for a required location as default and build.
If GPX file has a sequence of location then, Xcode will treat it as route and start navigation on the map as per given coordinates.

So you can also select this route from Xcode by clicking Location Services icon in the jump bar of the debug area. And user navigation will be simulated as per given GPX points.

Description

It’s time to land your dream job. If you are planning to build a career as an iOS Developer, prepare in advance with these frequently asked iOS interview questions. These iOS Developer interview questions have been answered by the top industry experts and have been proven to be helpful. Interview questions for ios Developer here will boost your knowledge and confidence in a short period of time. With these basic ios interview questions, you will be able to answers questions like What happens when the app receives a push notification?’, ‘Ways to Modify below code using Dependency Injection’, ‘What is the difference between the consumable and non-consumable type of in-app purchase?’. Be prepared and chase your dream job.
Levels