Objective C Interview Questions and Answers
Most Frequently Asked Objective C Interview Questions
An ANSI-based version of the standard C programming language, Objective-C is the key programming language used for mobile app development by companies that make apps for OS X and iOS. Objective-C is developed on top of C language by adding Small Talk features that make it an object-based language.
Objective-C was created by Tom Love and Brad Cox at their company Stepstone in the early 1980s.
Apple released Objective-C 2.0 at the Worldwide Developers Conference in 2006. It is its latest version.
A protocol announces a programmatic interface that a class chooses to implement. It enables two classes that are related by inheritance to “talk” with each other in order to accomplish a goal.
Protocols are of two types - formal and informal.
An extension of the Objective-C language, a formal protocol announces a list of methods that client classes are likely to implement.
An informal protocol is one of the categories on NSObject that makes all objects adopters of the protocol. Implementing methods in an informal protocol is optional.
#import function ensures a file is included only once so that you do not have a problem with recursive include.
import is a super set of include and it ensures file is included once.
A category is used to add methods to an existing class. The added methods are usually inherited by subclass and are difficult to differentiate from the original methods at runtime. Categories are used to distribute the implementation of their classes into separate source files.
#import “SystemClass.h”
@interface SystemClass (CategoryName)
// method declarations
@end
NSMutableArray is the subclass of NSArray and they both manage collections of objects known as arrays. NSArray is responsible for creating static arrays, whereas NSMutableArray is responsible for creating dynamic arrays.
The object is a collection of as an array or set of Cocoa classes that may include the collection classes. This collection of classes adopts the NSFastEnumeration protocol. This protocol can be used to retrieve elements that are held by an instance by using a syntax that is similar to a standard C for loop.
Look at this instance:
NSArray *anArray = // get an array;
for (id element in anArray)
{
/* code that acts on the element */
}
@synthesize creates getter and setter for the variables and allows you to specify attributes for variables. When you @synthesize the property to the variable, you generate getter and setter for that variable.