Objective C Interview Questions and Answers
Most Frequently Asked Objective C Interview Questions
This is how you call a function:
[className methodName]
For announcing methods in same class, use this:
[self methodName]
The dot syntax is a shortcut for calling getter and setter.
You can use this:
[foo length]
foo.length
are exactly the same, as are:
[foo setLength:5]
foo.length = 5
NSObject is the root class from which a lot of other classes inherit. When an object encounters another object, it interacts using the basic behavior defined by the NSObject description.
Atomic is the default behavior that ensures the present process is completed by the CPU.
Non-Atomic is not the default behavior and may result in unexpected behavior.
GCD refers to GrandcentralDispatch. GCD creates only one thread for executing the blocks and those blocks execute sequentially. The best thing about GCD is that the programmer does not have to create threads or match the number of threads to the available processors.
KVC stands for Key-Value-Coding. It refers to accessing a property or value using a string.
id someValue = [myObject valueForKeyPath:@”foo.bar.baz”];
Which could be the same as:
id someValue = [[[myObject foo] bar] baz];
KOC stands for Key-Value-Observing. It allows programmers to observe changes in property or value.
In order to observe a property using KVO, you should identify the property with a string. The observable object must be KVC compliant.
[myObject addObserver:self forKeyPath:@”foo.bar.baz” options:0 context:NULL];
You can dealloc for memory management. Once an object “retainCount” reaches 0, a dealloc message is sent to that object. Never call dealloc on objects unless you call [super dealloc]; around the close of a overridden dealloc.
(void)dealloc
{
[ivar release]; //Release any retained variables before super dealloc
[super dealloc]; //Only place in your code you should ever call dealloc
}
Blocks are language-level features that are added to Objective C, C, and C++. Blocks allow you to create segments of code that can be passed to methods or functions as values. Syntax to define a block uses the caret symbol (^):
^{
NSLog(@”This is a block”);
}
Responder chain is a series of responder objects that are linked together. A chain starts with the first responder and ends with the app object. However, when the first responder is unable to handle an event, it forwards it to the next responder in the chain.
- Well-tested and mature language
- Documented frameworks.
- Strong online support.
- Works smoothly with C and C++.
- Stable language.