InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What are NSAutoreleasePool and how can we use them? |
|
Answer» NSAutoreleasePool SUPPORTS Cocoa’s memory management system and it stores OBJECTS that are sent when the pool is drained. When you use Automatic Reference Counting, you cannot use autorelease POOLS. So, you should use @autoreleasepool blocks. For example, instead of: |
|
| 2. |
How dispatch_once runs only once? |
|
Answer» Because it is a synchronous PROCESS. The IDEA of dispatch_once() is to PERFORM a TASK only once, no matter how violent the threading becomes. |
|
| 3. |
What is a delegate? Can you retain delegates? |
|
Answer» It is an object that acts in coordination with, on behalf of, other objects when those objects encounter an EVENT in a program. If you WANT to retain a delegate, it can be RETAINED. However, the rule is not to retain it because it must E ALREADY retained you will avoid unnecessary retain cycles. |
|
| 4. |
Is there function overloading in Objective-C? |
|
Answer» No. Objective-C does not support overloading, so you will NEED to USE a DIFFERENT METHOD. |
|
| 5. |
What is an instanceType? |
|
Answer» @INTERFACE A: Here, the init method is INHERITED from A to B. HOWEVER, the method has a different return type in both CLASSES. |
|
| 6. |
What is id? |
|
Answer» It is a pointer to any type, but unlike a void *, it points to an object. For INSTANCE, you ADD anything of type id to an NSARRAY as long as those objects are responding to retain and release it. |
|
| 7. |
What are the advantages of using Objective-C? |
| Answer» | |
| 8. |
What are the blocks? How will you use them? |
|
Answer» 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 (^): 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. |
|
| 9. |
When should you call dealloc method? Is it possible to implement dealloc in ARC? |
|
Answer» 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. |
|
| 10. |
What are KVC and KVO? Provide an example. |
|
Answer» KVC stands for Key-VALUE-Coding. It refers to accessing a PROPERTY or value using a string.
|
|
| 11. |
What is GCD? What are its advantages over NSThread? |
|
Answer» 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. |
|
| 12. |
What is the difference between atomic and nonatomic synthesized properties? |
|
Answer» 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. |
|
| 13. |
Is NSObject a parent class or a derived class? |
|
Answer» 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. |
|
| 14. |
What is dot notation? |
|
Answer» The dot syntax is a shortcut for CALLING getter and setter. You can USE this: |
|
| 15. |
How to call function? |
|
Answer» This is how you call a FUNCTION: |
|
| 16. |
What is @synthesize? |
|
Answer» @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. |
|
| 17. |
What is fast enumeration? |
|
Answer» 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: |
|
| 18. |
When will you use NSArray and NSMutableArray? Which one is faster? |
|
Answer» 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. |
|
| 19. |
What is the function of the category? |
|
Answer» 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”
|
|
| 20. |
How is #import different from #include? |
|
Answer» #import function ENSURES a FILE is INCLUDED only once so that you do not have a problem with recursive include. |
|
| 21. |
What are the different types of protocols? |
|
Answer» Protocols are of two types - formal and INFORMAL. 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. |
|
| 22. |
What is protocol in Objective-C? |
|
Answer» 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. |
|
| 23. |
What is the latest version of objective-c? |
|
Answer» Apple RELEASED Objective-C 2.0 at the Worldwide DEVELOPERS CONFERENCE in 2006. It is its latest VERSION. |
|
| 24. |
Who introduced Objective-C & when? |
|
Answer» Objective-C was CREATED by TOM LOVE and Brad Cox at their COMPANY Stepstone in the early 1980s. |
|
| 25. |
What is Objective C & why it is used for? |
|
Answer» 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. |
|