iphone Interview Questions part-10

101-What is polymorphism?

This is very famous question and every interviewer asks this. Few people say polymorphism means multiple forms and they start giving example of draw function which is right to some extent but interviewer is looking for more detailed answer.

Ability of base class pointer to call function from derived class at runtime is called polymorphism.

For example, there is super class human and there are two subclasses software engineer and hardware engineer. Now super class human can hold reference to any of subclass because software engineer is kind of human. Suppose there is speak function in super class and every subclass has also speak function. So at runtime, super class reference is pointing to whatever subclass, speak function will be called of that class. I hope I am able to make you understand.

101-What is responder chain?

Suppose you have a hierarchy of views such like there is superview A which have subview B and B has a subview C. Now you touch on inner most view C. The system will send touch event to subview C for handling this event. If C View does not want to handle this event, this event will be passed to its superview B (next responder). If B also does not want to handle this touch event it will pass on to superview A. All the view which can respond to touch events are called responder chain. A view can also pass its events to uiviewcontroller. If view controller also does not want to respond to touch event, it is passed to application object which discards this event.

102-Can we use one tableview with two different datasources? How you will achieve this?

Yes. We can conditionally bind tableviews with two different data sources.

103-What is a protocol?

A protocol is a language feature in objective C which provides multiple inheritance in a single inheritance language. Objective C supports two types of protocols:

  • Ad hoc protocols called informal protocol
  • Compiler protocols called formal protocols

You must create your own autorelease pool as soon as the thread begins executing; otherwise, your application will leak objects

104-Three occasions when you might use your own autorelease pools:

  1. 1.    If you are writing a program that is not based on a UI framework, such as a command-line tool.
  2. 2.    If you write a loop that creates many temporary objects.You may create an autorelease pool inside the loop to dispose of those objects before the next iteration. Using an autorelease pool in the loop helps to reduce the maximum memory footprint of the application.
  3. 3.    If you spawn a secondary thread.

105- InApp purchase product type

  1. 1.    Consumable products must be purchased each time the user needs that item. For example, one-time services are commonly implemented as consumable products.
  2. 2.    Non-consumable products are purchased only once by a particular user. Once a non-consumable product is purchased, it is provided to all devices associated with that user’s iTunes account. Store Kit provides built-in support to restore non-consumable products on multiple devices.
  3. 3.    Auto-renewable subscriptions are delivered to all of a user’s devices in the same way as non-consumable products. However, auto-renewable subscriptions differ in other ways. When you create an auto-renewable subscription in iTunes Connect, you choose the duration of the subscription. The App Store automatically renews the subscription each time its term expires. If the user chooses to not allow the subscription to be renewed, the user’s access to the subscription is revoked after the subscription expires. Your application is responsible for validating whether a subscription is currently active and can also receive an updated receipt for the most recent transaction.
  4. 4.    Free subscriptions are a way for you to put free subscription content in Newsstand. Once a user signs up for a free subscription, the content is available on all devices associated with the user’s Apple ID. Free subscriptions do not expire and can only be offered in Newsstand-enabled apps

106-the advantages and disadvantages about synchronous versus asynchronous connections.

That’s it, pretty fast and easy, but there are a lot of caveats :

• The most important problem is that the thread which called this method will be blocked until the connection finish or timeout, so we surely don’t want to start the connection on the main thread to avoid freezing the UI. That means we need to create a new thread to handle the connection, and all programmers know that threading is hard.

• Cancellation, it’s not possible to cancel a synchronous connection, which is bad because users like to have the choice to cancel an operation if they think it takes too much time to execute.

• Authentication, there is no way to deal with authentication challenges.

• It’s impossible to parse data on the fly.

So let’s put it up straight, avoid using synchronousNSURLConnection, there is absolutely no benefit of using it.

It’s clear that asynchronous connections give us more control :

• You don’t have to create a new thread for the connection because your main thread will not be blocked.

• You can easily cancel the connection just by calling the cancelmethod.

• If you need authentication just implement the required delegate methods.

• Parsing data on the fly is easy.

So clearly we have a lot of more control with this, and the code is really not difficult.

Even better, we don’t have to handle the creation of a new thread, which is a good thing, because you know, threading is hard.

Well, if you read me until here, you should be convinced to use asynchronous connections, and forget about synchronous ones. They clearly give us more control and possibilities and, in some case can spare us to create new thread.

So I encourage you to move away from synchronous connections, just think of them as evil.

107-What is the navigation controller?

Navigation controller contains the stack of controllers every navigation controller
must be having root view controller by default these controllers contain 2 method
 
(a) push view (b) pop view
By default navigation controller contain “table view”.

108- What is the split view controller?

This control is used for ipad application and it contain proper controllers by default
split view controller contain root view controller and detail view controller.

109-Cocoa.

Cocoa is an application environment for both the Mac OS X operating system and iOS. It consists of a suite of object-oriented software libraries, a runtime system, and an integrated development environment. Carbon is an alternative environment in Mac OS X, but it is a compatibility framework with procedural programmatic interfaces intended to support existing Mac OS X code bases.

110- Frameworks that make Cocoa.

Appkit (Application Kit)

Foundation


Discover more from CODE t!ps

Subscribe to get the latest posts sent to your email.

Scroll to Top

Discover more from CODE t!ps

Subscribe now to keep reading and get access to the full archive.

Continue reading