Top IOS Interview Questions and Answers (August 2018) Part 3

This article contains recent interview experience of iOS engineer, i have collected questions from candidate and sharing with you, Hope it…

Top IOS Interview Questions and Answers (August 2018) Part 3

This article contains recent interview experience of iOS engineer, i have collected questions from candidate and sharing with you, Hope it will help you.

Q1. What will be the output for following program(look for sync/async)

Solution:

Q2. What will be the output for following program(look for sync/async)

Solution:

Q3. What will be the output for following program(look for sync/async),

will there be any error — compile time or run time and why?

Solution:

NEVER call the sync function on the main queue

If you call the sync function on the main queue it will block the queue as well as the queue will be waiting for the task to be completed but the task will never be finished since it will not be even able to start due to the queue is already blocked. It is called deadlock.

Q4. What will be the output for following program(look for sync/async)

Solution:

Q5. What is the entry point of iOS application in objective C?

Q6. What is the difference between delegate and data source?

Solution: Theoretically

The delegate and datasource patterns are largely independent, and orthogonal:

The delegate pattern is very common in Cocoa and allows a delegate (any instance implementing the informal delegate protocol prior to OS X 10.6, or the formal delegate @protocol in 10.6 and later) to modify the behavior of an object instance. This pattern is often used instead of subclassing: instead of subclassing a class to change its behavior, you supply a delegate that responds to the appropriate methods. Classes that use delegates send messages to their delegate at contracted events. The API between class and delegate is defined by the class and is different for each class that uses the pattern, but the API generally consists of messages asking the delegate how to handle a particular event. One advantage of the delegate pattern over subclassing is that a class may implement multiple delegate protocols, allowing its instances to act as delegate for multiple classes. Similarly, an object instance can be the delegate for multiple other objects (hence most delegate APIs pass the object as the first argument to each message in the API). The delegate pattern is not as common in other UI frameworks (though Qt does use the delegate pattern in its Model/View framework), and is not the same as .Net/CLR delegates which are essentially typed function pointers.

The data source pattern is often used by NSView sub-classes in Cocoa that have complex state data such as NSBrowser, NSTableView, NSOutlineView, etc. The data source protocol defines an API that instances of these (and other) classes may use to get the data to display in the view. Although the NSController and Cocoa Bindings architectures have replaced many uses of the data source pattern, it's still common and very powerful. Like the delegate pattern described above, part of its power comes from an object being able to act as the data source for multiple data-source-using instances (and possibly even instances of multiple classes that have different data source protocols). The data source pattern is used commonly in other UI frameworks, such as Qt (in the Model/View framework where the model is analogous to the data source) and WPF/Silverlight (where the data source might be more closely analogous to the view model).

Practically:

Delegates are for communication between classes , Data source is for providing runtime behavior to a class.

Q7. What is the difference between frame and bound?

Solution: