Objective-C Programming Interview Questions and Answers -Top Answers to Objective-C Interview Questions. Learn Objective-C programming language with simple and easy examples.
Objective-C is an object-oriented, general-purpose programming language that adds Smalltalk-style messaging to the C programming language. It was the main programming language used by Apple for the OS X and iOS operating systems, and their respective application programming interfaces (APIs) Cocoa and Cocoa Touch prior to the introduction of Swift. Objective-C is a fundamentally simple language. Its syntax is small, unambiguous, and easy to learn. Object-oriented programming, with its self-conscious terminology and emphasis on abstract design, often presents a steep learning curve to new recruits. A well-organized language like Objective-C can make becoming a proficient object-oriented programmer that much less difficult.
Objective-C supports an open style of dynamic binding, a style that can accommodate a simple architecture for interactive user interfaces. Messages are not necessarily constrained by either the class of the receiver or even the method name, so a software framework can allow for user choices at runtime and permit developers freedom of expression in their design. (Terminology means dynamic binding, message, class, and receiver )
The programming language Objective-C was originally developed in the early 1980s. It was selected as the main language used by NeXT for its Next STEP operating system, from which OS X and iOS are derived. Portable Objective-C programs that do not use the Cocoa or Cocoa Touch libraries, or those using parts that may be ported or re implemented for other systems, can also be compiled for any system supported by GNU Compiler Collection (GCC) or Clang.

What is Object C?
The Objective-C language is a programming language designed to enable sophisticated object-oriented programming. Objective-C is defined as a small but powerful set of extensions to the standard ANSI C language. Its additions to C are mostly based on Smalltalk, one of the first object-oriented programming languages. Objective-C is designed to give C full object-oriented programming capabilities and to do so in a simple and straightforward way. Objective-C inherits the syntax, primitive types, and flow control statements of C and adds syntax for defining classes and methods. It also adds language-level support for object graph management and object literals while providing dynamic typing and binding, deferring many responsibilities until runtime.
What is id in Objective C?
It's a generic C type that Objective-C uses for an arbitrary object. For example, a static function that takes one object as argument and returns an object, could be declared as:
Static id myfunction (id argument) {…}

Explain Cocoa/Cocoa Touch?
Cocoa and Cocoa Touch are the application development environments for OS X and iOS. Both Cocoa and Cocoa Touch include the Objective-C runtime and two core frameworks:
Cocoa: Cocoa includes the Foundation and AppKit frameworks and is used for developing applications that run on OS X.
Cocoa Touch: Cocoa Touch includes Foundation and UIKit frameworks. It is used for developing applications that run on iOS.

How do I make a static method in Objective –C?
Methods are always implemented in Objective-C as static functions. The only way to obtain the IMP (implementation pointer) of a method is through the runtime (via method For: and friends), because the function itself is static to the file that implements the method.

How can I link a C++ library into an Objective-C program?
There are two options: either use the Apple compiler or use the POC.
The former accepts a mix of C++ and Objective-C syntax (called Objective-C++), the latter compiles Objective-C into C and then compiles the intermediate code with a C++ compiler

What is OOP?
OOP is the acronym for Object Oriented Programming. It is a type of programming method which helps to organize a set of objects in a system. With the use of various programming languages, this method aids to develop several computer programs and applications.

Explain how is objective C and OOP related?
Objective C is a type of programming language which helps in the process of object oriented programming. It basically provides an extension to ANSI C standard... - you can expand your answer though related examples and concepts.

Where is this language most commonly used and by whom?
Objective C has been developed by Apple for their OS X and iOS operating system and API's, Cocoa and Cocoa Touch. This programming language helps to develop their process and application for iPhone and Mac system.
What is a protocol?
A protocol is a language feature in objective C which provides multiple inheritance in a single inheritance language. Objective C supports two types of protocols:
Ad hoc protocols called informal protocol
Compiler protocols called formal protocols

How do I allocate an object on the stack?
To allocate an instance of 'MyClass' on the stack:
MyClass aClass = [MyClass new];

What is the difference between interface in Java and protocol on objective C?
Protocols and interfaces are used to retrieve multiple inheritance. The only difference between them is that in Java. Java offers abstract classes and interfaces whereas Objective-C has header files and protocols. Objective-C is a superset of C, so it's faster and has access to all of C (as well as all of C++ if you know what you're doing)

What is App Bundle?
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.

What is inheritance in Objective-C?
Inheritance is one of the basic features of object oriented programming. This feature allows to develop and design a new class from a base class. The process is conducted with the use of the existing class.

What do you mean by keyword atomic in Objective C?
When keyword atomic is used, it allows the accessibility of only one thread.

How to call the function in Objective-C?
To call the function in Objective-C, you have to do Account -> Object Name -> Display account information -> Method name

What are objective- C blocks?
In Objective-C class, there is an object that combines data with related behavior.  It enables you to form distinct segments of code that can be passed around to functions or methods as if they were values.  Objective-C blocks can be added to collections like NSDictionary or NSArray

What is the difference between mutable and immutable types in Objective C?
Mutable in objective C allows to make changes in content or values at any point of time. But immutable objects cannot be changed once they are placed.

What is an IMP in Objective –C?
It's the C type of a method implementation pointer, a function pointer to the function that implements an Objective-C method. It is defined to return id and takes two hidden arguments, self and _cmd: typedef id (*IMP)(id self,SEL _cmd,…);

What is the difference between abstraction and polymorphism?
Abstraction in OOP is the process of diminishing the unwanted data and keeping only the relevant data for the users, while polymorphism allows an object to perform their functions in two or more forms.

Name the framework that is used to construct application’s user interface for iOS?
The UIKit framework is used to develop application’s user interface for iOS. UIKit framework provides event handling, drawing model, windows, views, and controls specifically designed for a touch screen interface.

What do you understand by push notification in Objective C?
Apple has developed this service, where a server sends a notification about a new information or data in the system. - It will be better if you can also explain with example of push notification flow.

Explain assign, weak, retain and copy in Objective C?
Assign: It is use assign to set a property’s pointer to the address of the object without retaining it.
Weak: It is use weak to have the property point to nil automatically if the object assigned to be deallocated. IBOutlets are weak and point to nil automatically when not on screen.
Retain : It is Declared properties use retain by default and will manage the object’s reference count automatically whether another object is assigned to the property or it’s set to nil.
Copy: It is Creates a copy of the object. This creates another object that you can modify. Often used with strings because making a copy of the original object ensures that it will not change whilst you are using it.

How do I get an IMP given a SEL in Objective –C?
This can be done by sending a methodFor: message:
IMP myImp = [myObject methodFor:mySel];

What is difference between shallow copy and deep copy?
Shallow copy: Shallow copy is also known as address copy. In this process you only copy address not actual data while in deep copy you copy data.
Deep copy: deep copy data is also copied. This process is slow but Both A and B have their own copies and changes made to any copy, other will copy will not be affected.

How do I include X Intrinsics headers into an Objective-C file?
To avoid a conflict between Objective-C's Object and the X11/Object, do the following:
#include <Object.h>
#define Object XtObject
#include <X11/Intrinsic.h>
#include <X11/IntrinsicP.h>
#undef Object

Explain when you send autorelease or retain message to autorelease pool?
NSAutoreleasePool  *autoRelease =[ [[ NSAutoreleasePool alloc] init] autorelease]; or
NSAutoreleasePool  *autoRelease =[ [[ NSAutoreleasePool alloc] init] retain];

What's the class of a constant string?
It's an NXConstantString.
NXConstantString *myString = @"my string";

What happens when you invoke a method on a nil pointer?
A message sent to nil object is perfectly acceptable in Objective-C, it’s treated as a no-op. There is no way to flag it as an error because it’s not an error, in fact, it can be a very useful feature of the language.

If I call perform Selector: with Object: after Delay:  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.

How messaging works in Objective-C?
Messaging are not bound to method implementation until runtime in Objective-C. The compiler transforms a message expression, into a call on a messaging function, objc_msgSend ().  This function connects the receiver and the name of the method mentioned in the message.
Request to Download PDF

Post A Comment:

0 comments: