Monday 3 October 2016

IOS Interview Questions With Answers



*Q: How would you create your own custom view?
A:By Subclassing the UIView class.

*Q: What is App Bundle?
A:When you build your iOS app, Xcode packages it as a bundle. A bundle is a directory in the file system that groups related resources together in one place. An iOS app bundle contains the app executable file and supporting resource files such as app icons, image files, and localized content.

*Q: Whats fast enumeration?
A:Fast enumeration is a language feature that allows you to enumerate over the contents of a collection. (Your code will also run faster because the internal implementation reduces message send overhead and increases pipelining potential.)

*Q: Whats a struct?
A:A struct is a special C data type that encapsulates other pieces of data into a single cohesive unit. Like an object, but built into C.

*Q: Whats the difference between  NSArray and  NSMutableArray?
A:NSArrayʼs contents can not be modified once itʼs been created whereas a NSMutableArray can be modified as needed, i.e items can be added/removed from it.

*Q: Explain retain counts.
A:Retain counts are the way in which memory is managed in Objective-C. When you create an object, it has a retain count of 1. When you send an object a retain message, its retain count is incremented by 1. When you send an object a release message, its retain count is decremented by 1. When you send an object a autorelease message, its retain count is decremented by 1 at some stage in the future. If an objectʼs retain count is reduced to 0, it is deallocated.

This will explain how the memory management is done in iOS
This will explain how the memory management is done in iOS
*Q: Whats the difference between frame and bounds?
A:The frame of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within. The bounds of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).

*Q: Is a delegate retained?
A:No, the delegate is never retained! Ever!

*Q:Outline the class hierarchy for a UIButton until NSObject.
A:UIButton inherits from UIControl, UIControl inherits from UIView, UIView inherits from UIResponder, UIResponder inherits from the root class NSObject.

*Q:What are the App states. Explain them?
A:Not running State:  The app has not been launched or was running but was terminated by the system.
Inactive state: The app is running in the foreground but is currently not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state. The only time it stays inactive for any period of time is when the user locks the screen or the system prompts the user to respond to some event, such as an incoming phone call or SMS message.
Active state: The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.
Background state:  The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state. For information about how to execute code while in the background, see “Background Execution and Multitasking.”
Suspended state:The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code. When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.

*Q: Explain how the push notification works.
A:Push-Overview

*Q: Explain the steps involved in submitting the App to App-Store.
A:Apple provides the tools you need to develop, test, and submit your iOS app to the App Store. To run an app on a device, the device needs to be provisioned for development, and later provisioned for testing. You also need to provide information about your app that the App Store displays to customers and upload screenshots. Then you submit the app to Apple for approval. After the app is approved, you set a date the app should appear in the App Store as well as its price. Finally, you use Apple’s tools to monitor the sales of the app, customer reviews, and crash reports. Then you repeat the entire process again to submit updates to your app.

*Q: Why do we need to use @Synthesize?
A:We can use generated code like nonatomic, atmoic, retain without writing any lines of code. We also have getter and setter methods. To use this, you have 2 other ways: @synthesize or @dynamic: @synthesize, compiler will generate the getter and setter automatically for you, @dynamic: you have to write them yourself.@property is really good for memory management, for example: retain.How can you do retain without @property?

if (_variable != object)

{

    [_variable release];

    _variable = nil;

    _variable = [object retain];

    }

How can you use it with @property?self.variable = object; When we are calling the above line, we actually call the setter like [self setVariable:object] and then the generated setter will do its job.

*Q: Multitasking support is available from which version?
A:iOS 4.0.

*Q: How many bytes we can send to apple push notification server?
A:256bytes.

*Q: Can you just explain about memory management in iOS?
A:Refer: iOS Memory Management

*Q: What is code signing?
A:Signing an application allows the system to identify who signed the application and to verify that the application has not been modified since it was signed. Signing is a requirement for submitting to the App Store (both for iOS and Mac apps). OS X and iOS verify the signature of applications downloaded from the App Store to ensure that they they do not run applications with invalid signatures. This lets users trust that the application was signed by an Apple source and hasn’t been modified since it was signed.



Xcode uses your digital identity to sign your application during the build process. This digital identity consists of a public-private key pair and a certificate. The private key is used by cryptographic functions to generate the signature. The certificate is issued by Apple; it contains the public key and identifies you as the owner of the key pair.

In order to sign applications, you must have both parts of your digital identity installed. Use Xcode or Keychain Access to manage your digital identities. Depending on your role in your development team, you may have multiple digital identities for use in different contexts. For example, the identity you use for signing during development is different from the identity you user for distribution on the App Store. Different digital identities are also used for development on OS X and on iOS.

An application’s executable code is protected by its signature because the signature becomes invalid if any of the executable code in the application bundle changes. Resources such as images and nib files are not signed; a change to these files does not invalidate the signature.

An application’s signature can be removed, and the application can be re-signed using another digital identity. For example, Apple re-signs all applications sold on the App Store. Also, a fully-tested development build of your application can be re-signed for submission to the App Store. Thus the signature is best understood not as indelible proof of the application’s origins but as a verifiable mark placed by the signer.

*Q:   Explain the options and bars available in xcode 4.x workspace window ?
A: [block]1[/block]

*Q: If I call performSelector:withObject:afterDelay: – is the object retained?
A:

Yes, the object is retained. It creates a timer that calls a selector on the current threads run loop. It may not be 100% precise time-wise as it attempts to dequeue the message from
the run loop and perform the selector.

*Q: Can you explain what happens when you call autorelease on an object?
A:When you send an object a autorelease message, its retain count is decremented by 1 at some stage in the future. The object is added to an autorelease pool on the current thread. The main thread loop creates an autorelease pool at the beginning of the function, and release it at the end. This establishes a pool for the lifetime of the task. However, this also means that any autoreleased objects created during the lifetime of the task are not disposed of until the task completes. This may lead to the taskʼs memory footprint increasing unnecessarily. You can also consider creating pools with a narrower scope or use NSOperationQueue with itʼs own autorelease pool. (Also important – You only release or autorelease objects you own.)

*Q: Whats the NSCoder class used for?
A:

NSCoder is an abstractClass which represents a stream of data. They are used in Archiving and Unarchiving objects. NSCoder objects are usually used in a method that is being implemented so that the class conforms to the protocol. (which has something like encodeObject and decodeObject methods in them).

*Q: Whats an NSOperationQueue and how/would you use it?
A:The NSOperationQueue class regulates the execution of a set of NSOperation objects. An operation queue is generally used to perform some asynchronous operations on a background thread so as not to block the main thread.

*Q: Explain the correct way to manage Outlets memory.
A:Create them as properties in the header that are retained. In the viewDidUnload set the outlets to nil(i.e self.outlet = nil). Finally in dealloc make sure to release the outlet.

iOS interview Questions for  Expert level


*Q:What is sandbox?
A:For security reasons, iOS places each app (including its preferences and data) in a sandbox at install time. A sandbox is a set of fine-grained controls that limit the app’s access to files, preferences, network resources, hardware, and so on. As part of the sandboxing process, the system installs each app in its own sandbox directory, which acts as the home for the app and its data.

To help apps organize their data, each sandbox directory contains several well-known subdirectories for placing files. Above Figure shows the basic layout of a sandbox directory.

*Q:Is the delegate for a CAAnimation retained?
A:Yes it is!! This is one of the rare exceptions to memory management rules.

 *Q: What is dynamic?
A:You use the @dynamic keyword to tell the compiler that you will fulfill the API contract implied by a property either by providing method implementations directly or at runtime using other mechanisms such as dynamic loading of code or dynamic method resolution. It suppresses the warnings that the compiler would otherwise generate if it can’t find suitable implementations. You should use it only if you know that the methods will be available at runtime.
*Q: What happens when the following code executes?
Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];

A:It will crash because itʼs added twice to the autorelease pool and when it it dequeued the autorelease pool calls release more than once.

*Q: Explain the difference between NSOperationQueue concurrent and non-concurrent.
A:In the context of an NSOperation object, which runs in an NSOperationQueue, the terms concurrent and non-concurrent do not necessarily refer to the side-by-side execution of threads. Instead, a non-concurrent operation is one that executes using the environment that is provided for it while a concurrent operation is responsible for setting up its own execution environment.

*Q: Implement your own synthesized methods for the property NSString *title.
A:Well you would want to implement the getter and setter for the title object. Something like this: view source print?

– (NSString*) title // Getter method

{

return title;

}

– (void) setTitle: (NSString*) newTitle //Setter method

{

if (newTitle != title)

{

[title release];

title = [newTitle retain]; // Or copy, depending on your needs.

}

}

*Q: Implement the following methods: retain, release, autorelease.
A:-(id)retain

{

NSIncrementExtraRefCount(self);

return self;

}

-(void)release

{

if(NSDecrementExtraRefCountWasZero(self))

{NSDeallocateObject(self);

}

}

-(id)autorelease

{ // Add the object to the autorelease pool

[NSAutoreleasePool addObject:self];

return self;

}

*Q: What are all  the newly added frameworks iOS 4.3 to iOS 5.0?
A:Accounts
 CoreBluetooth
 CoreImage
 GLKit
 GSS
 NewsstandKit
 Twitter
*Q: What is Automatic Reference Counting (ARC) ?
A:ARC is a compiler-level feature that simplifies the process of managing the lifetimes of Objective-C objects. Instead of you having to remember when to retain or release an object, ARC evaluates the lifetime requirements of your objects and automatically inserts the appropriate method calls at compile time.

*Q: What is the difference between retain & assign?
A:Assign creates a reference from one object to another without increasing the source’s retain count.

if (_variable != object)

{

 [_variable release];

  _variable = nil;

  _variable = object;

 }

Retain creates a reference from one object to another and increases the retain count of the source object.

if (_variable != object)

{

  [_variable release];

    _variable = nil;

_variable = [object retain];

}

*Q: What is Controller Object?
A:A controller object acts as a coordinator or as an intermediary between one or more view objects and one or more model objects. In the Model-View-Controller design pattern, a controller object (or, simply, a controller) interprets user actions and intentions made in view objects—such as when the user taps or clicks a button or enters text in a text field—and communicates new or changed data to the model objects.image: Art/controller_object.jpg

 When model objects change—for example, the user opens a document stored in the file system—it communicates that new model data to the view objects so that they can display it. Controllers are thus the conduit through which view objects learn about changes in model objects and vice versa. Controller objects can also set up and coordinate tasks for an application and manage the life cycles of other objects. The Cocoa frameworks offer three main controller types: coordinating controllers, view controllers (on iOS), and mediating controllers (on OS X).

*Q: What is Wildcard App IDs?
A:A wildcard app ID allows you to use an app ID to match multiple apps; wildcard app IDs are useful when you first start developing new apps because you don’t need to create a separate app ID for each app. However, wildcard app IDs can’t be used to provision an app that uses APNS, In App Purchase, or Game Center.

A wildcard app ID omits some or all of the bundle ID in the search string and replaces that portion with an asterisk character (*). The asterisk must always appear as the last character in the bundle search string.

When you use a wildcard app ID, characters preceding the asterisk (if any) must match the characters in the bundle ID, exactly as they would for an explicit app ID. The asterisk matches all remaining characters in the bundle ID. Further, the asterisk must match at least one character in the bundle ID. This table shows an example search string and how it matches some bundle IDs but not others.

image: Art/app_ids_examples.jpg
If an app id uses an * as the bundle ID, then the search string matches any bundle ID.



*Q: What is categories in iOS?
A:We use categories to define additional methods of an existing class—even one whose source code is unavailable to you—without subclassing. You typically use a category to add methods to an existing class, such as one defined in the Cocoa frameworks. The added methods are inherited by subclasses and are indistinguishable at runtime from the original methods of the class. You can also use categories of your own classes to:

Distribute the implementation of your own classes into separate source files—for example, you could group the methods of a large class into several categories and put each category in a different file.
Declare private methods.
You add methods to a class by declaring them in an interface file under a category name and defining them in an implementation file under the same name. The category name indicates that the methods are an extension to a class declared elsewhere, not a new class.

Refer: Categories and Extensions

*Q: What is Delegation in iOS?
A:Delegation is a design pattern in which one object sends messages to another object—specified as its delegate—to ask for input or to notify it that an event is occurring. Delegation is often used as an alternative to class inheritance to extend the functionality of reusable objects. For example, before a window changes size, it asks its delegate whether the new size is ok. The delegate replies to the window, telling it that the suggested size is acceptable or suggesting a better size. (For more details on window resizing, see the [block]2[/block] message.)



Delegate methods are typically grouped into a protocol. A protocol is basically just a list of methods. The delegate protocol specifies all the messages an object might send to its delegate. If a class conforms to (or adopts) a protocol, it guarantees that it implements the required methods of a protocol. (Protocols may also include optional methods).In this application, the application object tells its delegate that the main startup routines have finished by sending it the [block]3[/block] message. The delegate is then able to perform additional tasks if it wants.

*Q: How can we achieve singleton pattern in iOS?
A:The Singleton design pattern ensures a class only has one instance, and provides a global point of access to it. The class keeps track of its sole instance and ensures that no other instance can be created. Singleton classes are appropriate for situations where it makes sense for a single object to provide access to a global resource.

Several Cocoa framework classes are singletons.

They include [block]4[/block], NSWorkspace, NSApplication, and, in UIKit, [block]5[/block]. A process is limited to one instance of these classes. When a client asks the class for an instance, it gets a shared instance, which is lazily created upon the first request.Refer: Singleton Pattren

*Q: What is delegate pattern in iOS?
A:Delegation is a mechanism by which a host object embeds a weak reference (weak in the sense that it’s a simple pointer reference, unretained) to another object—its delegate—and periodically sends messages to the delegate when it requires its input for a task. The host object is generally an “off-the-shelf” framework object (such as an NSWindow or [block]7[/block]object) that is seeking to accomplish something, but can only do so in a generic fashion. The delegate, which is almost always an instance of a custom class, acts in coordination with the host object, supplying program-specific behavior at certain points in the task (see Figure 4-3). Thus delegation makes it possible to modify or extend the behavior of another object without the need for subclassing.

*Q: What are all the difference between categories and subclasses? Why should we go to subclasses?
A:Category is a feature of the Objective-C language that enables you to add methods (interface and implementation) to a class without having to make a subclass. There is no runtime difference—within the scope of your program—between the original methods of the class and the methods added by the category. The methods in the category become part of the class type and are inherited by all the class’s subclasses.As with delegation, categories are not a strict adaptation of the Decorator pattern, fulfilling the intent but taking a different path to implementing that intent. The behavior added by categories is a compile-time artifact, and is not something dynamically acquired. Moreover, categories do not encapsulate an instance of the class being extended.The Cocoa frameworks define numerous categories, most of them informal protocols . Often they use categories to group related methods. You may implement categories in your code to extend classes without subclassing or to group related methods. However, you should be aware of these caveats:

You cannot add instance variables to the class.
If you override existing methods of the class, your application may behave unpredictably.


*Q: What is notification in iOS?
A:The notification mechanism of Cocoa implements one-to-many broadcast of messages based on the Observer pattern. Objects in a program add themselves or other objects to a list of observers of one or more notifications, each of which is identified by a global string (the notification name). The object that wants to notify other objects—the observed object—creates a notification object and posts it to a notification center. The notification center determines the observers of a particular notification and sends the notification to them via a message. The methods invoked by the notification message must conform to a certain single-parameter signature. The parameter of the method is the notification object, which contains the notification name, the observed object, and a dictionary containing any supplemental information.Posting a notification is a synchronous procedure. The posting object doesn’t regain control until the notification center has broadcast the notification to all observers. For asynchronous behavior, you can put the notification in a notification queue; control returns immediately to the posting object and the notification center broadcasts the notification when it reaches the top of the queue.Regular notifications—that is, those broadcast by the notification center—are intraprocess only. If you want to broadcast notifications to other processes, you can use the istributed notification center and its related API.

*Q:What is the difference between delegates and notifications?
A:We can use notifications for a variety of reasons. For example, you could broadcast a notification to change how user-interface elements display information based on a certain event elsewhere in the program. Or you could use notifications as a way to ensure that objects in a document save their state before the document window is closed. The general purpose of notifications is to inform other objects of program events so they can respond appropriately.But objects receiving notifications can react only after the event has occurred. This is a significant difference from delegation. The delegate is given a chance to reject or modify the operation proposed by the delegating object. Observing objects, on the other hand, cannot directly affect an impending operation.

*Q:What is posing in iOS?
A:Objective-C permits a class to entirely replace another class within an application. The replacing class is said to “pose as” the target class. All messages sent to the target class are then instead received by the posing class. There are some restrictions on which classes can pose:
A class may only pose as one of its direct or indirect superclasses
The posing class must not define any new instance variables which are absent from the target class (though it may define or override methods).
No messages must have been sent to the target class prior to the posing.
Posing, similarly to categories, allows globally augmenting existing classes. Posing permits two features absent from categories:
A posing class can call overridden methods through super, thus incorporating the implementation of the target class.
A posing class can override methods defined in categories.


*Q:What is atomic and nonatomic? Which one is safer? Which one is default?
A:You can use this attribute to specify that accessor methods are not atomic. (There is no keyword to denote atomic.)

nonatomic
Specifies that accessors are nonatomic. By default, accessors are atomic.
Properties are atomic by default so that synthesized accessors provide robust access to properties in a multithreaded environment—that is, the value returned from the getter or set via the setter is always fully retrieved or set regardless of what other threads are executing concurrently.

If you specify strong, copy, or retain and do not specify nontoxic, then in a reference-counted environment, a synthesized get accessor for an object property uses a lock and retains and autoreleases the returned value—the implementation will be similar to the following:

[_internal lock]; // lock using an object-level lock
id result = [[value retain] autorelease];
[_internal unlock];
return result;
If you specify nonatomic, a synthesized accessor for an object property simply returns the value directly.

Markup and Deprecation

Properties support the full range of C-style decorators. Properties can be deprecated and support __attribute__ style markup:

@property CGFloat x
AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
@property CGFloat y __attribute__((…));


*Q: What is run loop in iOS ?
A:Run loops are part of the fundamental infrastructure associated with threads. A run loop is an event processing loop that you use to schedule work and coordinate the receipt of incoming events. The purpose of a run loop is to keep your thread busy when there is work to do and put your thread to sleep when there is none.

Run loop management is not entirely automatic. You must still design your thread’s code to start the run loop at appropriate times and respond to incoming events. Both Cocoa and Core Foundation provide run loop objects to help you configure and manage your thread’s run loop. Your application does not need to create these objects explicitly; each thread, including the application’s main thread, has an associated run loop object. Only secondary threads need to run their run loop explicitly, however. In both Carbon and Cocoa applications, the main thread automatically sets up and runs its run loop as part of the general application startup process.

*Q: What isDynamic typing?
A: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.

*Q: What is push notification?How it works?
A:Push-Overview

*Q: What is the configuration file name in iOS explain in brief ? (Or) What is plist file and explain about it is usage?
A:A property list is a representation of a hierarchy of objects that can be stored in the file system and reconstituted later. Property lists give applications a lightweight and portable way to store small amounts of data. They are hierarchies of data made from specific types of objects—they are, in effect, an object graph. Property lists are easy to create programmatically and are even easier to serialize into a representation that is persistent. Applications can later read the static representation back into memory and recreate the original hierarchy of objects. Both Cocoa Foundation and Core Foundation have APIs related to property list serialization and deserialization.

Property lists consist only of certain types of data: dictionaries, arrays, strings, numbers (integer and float), dates, binary data, and Boolean values. Dictionaries and arrays are special types because they are collections; they can contain one or multiple data types, including other dictionaries and arrays. This hierarchical nesting of objects creates a graph of objects. The abstract data types have corresponding Foundation classes, Core Foundation types, and XML elements for collection objects and value objects.

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home