iOS Interview Questions -Part i
iOS Interview Questions -Part ii
iOS Interview Questions -Part iii
iOS Interview Questions -Part iv
iOS Interview Questions -Part v
iOS Interview Questions -Part vi
iOS Interview Questions -Part vii
iOS Interview Questions -Part viii
iOS Interview Questions -Part ix
iOS Interview Questions -Part ii
iOS Interview Questions -Part iii
iOS Interview Questions -Part iv
iOS Interview Questions -Part v
iOS Interview Questions -Part vi
iOS Interview Questions -Part vii
iOS Interview Questions -Part viii
iOS Interview Questions -Part ix
133.What is the MVC software architecture pattern?
- What Most People Say:MVC is the pattern all well-written applications use.
- What You Should Say:The Model-View-Controller pattern separates the internal representation of data from its display. The model is the internal representation of the data, while the view is how the data is presented to the user. The controller mediates between the two and also handles user interaction.
- Why You Should Say It:“Candidates sound evasive when they don’t explain what MVC is or how it’s used,” says Schweitzer. “An incomplete answer makes it seem like you don’t understand the purpose of MVC software architecture patterns.”
134.What is the difference between a delegate and an NSNotification?
- What Most People Say:They are different ways of accomplishing the same thing. They are completely different and are used in different ways.
- What You Should Say:Delegates and NSNotifications can be used to accomplish nearly the same functionality. However, delegates are one-to-one while NSNotifications are one-to-many.
- Why You Should Say It:Developers who don’t know the answer to a technical question often resort to double speak, which never works. Instead, demonstrate your experience with delegates and NSNotifications by explaining how they’re used and the advantages and disadvantages of each.
135.What is a block and how is it used?
- What Most People Say: A block is a function.
- What You Should Say:A block is a chunk of code that can be passed to a method. The code is executed based on what happens in the method. Apple is moving many of the iOS APIs toward blocks.
- Why You Should Say It:First and foremost, “a block is not a function,” observes Schweitzer. “The second answer is not only accurate, it shows that you’re following the trends, which is critical for a developer.”
136.What’s the difference between a xib and a storyboard?
- What Most People Say:They’re the same thing.
- What You Should Say:Both are used in Xcode to layout screens (view controllers). A xib defines a single view controller screen, while a storyboard shows many view controllers and also shows the relationship between them. Apple is encouraging developers to use storyboards for all their applications.
- Why You Should Say It:“The interviewer isn’t trying to trick you,” says Schweitzer. “Storyboards and xib files are similar but they’re not exactly the same. He wants you to differentiate the two and explain their advantages and disadvantages.”
137.What is CoreData?
- What Most People Say:CoreData is Apple’s way of storing data on the disk.
- What You Should Say:CoreData is an SQLite database API. By setting up CoreData properly, an application can store and retrieve the internal state of a class rapidly.
- Why You Should Say It:Incorporating details into your answers demonstrates your understanding of the concept and inspires confidence.
138.How would you create your own custom view?
By Subclassing the UIView class.
By Subclassing the UIView class.
139.Whats fast enumeration?
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)
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)
140.Whats a struct?
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.
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.
141.What are mutable and immutable types in Objective C?
Mutable means you can change its contents later but when you mark any object immutable, it means once they are initialized, their values cannot be changed. For example, NSArray, NSString values cannot be changed after initialized.
Mutable means you can change its contents later but when you mark any object immutable, it means once they are initialized, their values cannot be changed. For example, NSArray, NSString values cannot be changed after initialized.
142.Explain retain counts.
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.
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.
143.Whats the difference between frame and bounds?
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).
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).
144.Is a delegate retained?
No, the delegate is never retained! Ever!
No, the delegate is never retained! Ever!
145.Outline the class hierarchy for a UIButton until NSObject.
UIButton inherits from UIControl, UIControl inherits from UIView, UIView inherits from UIResponder, UIResponder inherits from the root class NSObject.
UIButton inherits from UIControl, UIControl inherits from UIView, UIView inherits from UIResponder, UIResponder inherits from the root class NSObject.
146.What is dynamic?
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.
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.
147.If I call performSelector:withObject:afterDelay: – is the object retained?
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.
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.
148.Can you explain what happens when you call autorelease on an object?
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.)
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.)
149.Whats the NSCoder class used for?
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).
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).
150.Whats an NSOperationQueue and how/would you use it?
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.
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.
151.Explain the correct way to manage Outlets memory
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.
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.
152.Is the delegate for a CAAnimation retained?
Yes it is!! This is one of the rare exceptions to memory management rules.
Yes it is!! This is one of the rare exceptions to memory management rules.
153.What happens when the following code executes?
Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];
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.
Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];
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.
154.Explain the difference between NSOperationQueue concurrent and non-concurrent.
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.
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.
155.Implement your own synthesized methods for the property NSString *title.
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.
}
}
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.
}
}
156.Implement the following methods: retain, release, autorelease.
-(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
-(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
157.What is Automatic Reference Counting (ARC) ?
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.
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.
158.Multitasking support is available from which version?
iOS 4 and above supports multi-tasking and allows apps to remain in the background until they are launched again or until they are terminated.
iOS 4 and above supports multi-tasking and allows apps to remain in the background until they are launched again or until they are terminated.
159.How many bytes we can send to apple push notification server.
256bytes.
256bytes.
160.What is the difference between retain & assign?
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];
}
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];
}
161.Why do we need to use @Synthesize?
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
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
162.What is categories in iOS?
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.
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.
163.What is Delegation in iOS?
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 thewindowWillResize:toSize: 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 theapplicationDidFinishLaunching: message. The delegate is then able to perform additional tasks if it wants.
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 thewindowWillResize:toSize: 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 theapplicationDidFinishLaunching: message. The delegate is then able to perform additional tasks if it wants.
164.How can we achieve singleton pattern in iOS?
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 includeNSFileManager, NSWorkspace, NSApplication, and, in UIKit,UIApplication. 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.
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 includeNSFileManager, NSWorkspace, NSApplication, and, in UIKit,UIApplication. 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.
165.What is delegate pattern in iOS?
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 NSXMLParserobject) 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.Refer: delegate pattern
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 NSXMLParserobject) 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.Refer: delegate pattern
FabGreenTechnologies-Madivala
FabGreenTechnologies.com
FabGreenTechnologies.com
No comments:
Post a Comment