Significant IOS Interview Questions


Q6: Explain the concept of Completion Handler?

Ans: When the app is calling for an API, and we need to perform a certain action after a task reaches completion, completion handlers come in handy. For example, when you are updating the UI for displaying the data from the API call. In Apple’s APIs, you can see the completion handlers, such as dataTaskWithRequest. They can be very convenient in your own code.

With 3 arguments that are NSData?, NSURLResponse?, NSError?, the completion handler takes a piece of code that doesn’t return anything. As they executed when the execution of the enclosing function, they must mark @escaping.

Q7: In what ways you can specify the layout of elements in UIView?

Ans: Following are the ways that are often used for the specification of the layout of elements in UIView.

  • InterfaceBuilder: by using it, you get the option to add a XIB file to your project, and the layout elements present in it. After that, you can load XIB in your application code automatically depending on naming conventions, or manually. Moreover, this helps in making a storyboard for your application.
  • For using NSLayoutConstraints, you can write your own code. Plus, the Auto layout arranges elements in a view.
  • For every element, you can create CGRects to define the exact coordinates. Then, they can be passed to the UIView’s (id)initWithFrame:(CGRect)frame method.

Q8: What makes Synchronous & Asynchronous tasks different from each other?

Ans: It is almost clear from the name that synchronous is in order. In case you are performing the synchronous operation, everything that is supposed to take place after the operation must wait for it to be completed prior to proceeding.

On the other hand, asynchronous doesn’t have an order. When you perform a task asynchronously, you are allowed to run the next code without waiting. Eventually, the asynchronous process is going to happen. You can run on a different thread from the rest of the code. It is not difficult to reschedule it on the same thread later. You get notified when it is done.

Q9: Define an autorelease pool?

Ans: Whenever autorelease is sent to an object, it is included in the inner part of the autorelease pool. After this pool gets drained, to every object in the pool, it sends a release message.

Autorelease pool blocks allow a mechanism due to which a user can let go of the ownership of an object but avoid the chances of its immediate deallocation. Usually, there is no need for you to create your own autorelease pool blocks. However, in some scenarios, you have to do it or it is in your benefit to do it. In Swift, the autorelease pool pattern is used when you want to return autorelease objects.

Q10: What is ABI?

Ans: There are a few applications that use external libraries. For such applications, ABIs are essential. Suppose a program is designed to use a specific library and that library is updated after using it for some amount of time, you don’t want to re-compile that application. And, a user may not have the source do it.

In that situation, if the updated version of the library uses the previous ABI, then there is no need for the program to change. With Swift 5.0, ABI stability will be introduced. Once the ABI is stable, it will be persistent for the entire lifetime of a platform.