• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Objective C Interview Questions and Answers

by admin

What is #import?

It’s a C preprocessor construct to avoid multiple inclusions of the same file.

#import <Object.h>

is an alternative to:

#include <Object.h>

where the .h file is protected itself against multiple inclusions:

#ifndef _OBJECT_H_
…
#define _OBJECT_H_
#endif

What is id?

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) { ... }

What is an IMP?

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,...);

How do I get an IMP given a SEL?

This can be done by sending a methodFor: message:

IMP myImp = [myObject methodFor:mySel];

How can I link a C++ library into an Objective-C program?

You have 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.

How do I make a static method?

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 methodFor: and friends) because the function itself is static to the file that implements the method.

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

How do I allocate an object on the stack?

To allocate an instance of ‘MyClass’ on the stack:

MyClass aClass = [MyClass new];

What’s the class of a constant string?

It’s an NXConstantString.

NXConstantString *myString = @"my string";

Filed Under: Interview Questions

Some more articles you might also be interested in …

  1. Oracle RAC Interview Questions – Highly Available IP (HAIP)
  2. DHCP Interview Questions and Answers
  3. HP Unix Interview Questions and Answers
  4. SAP Interview Questions and Answers
  5. LDAP Interview Questions and Answers
  6. Oracle Database Interview Questions : Redo Logs and Archiving
  7. Load Balancer Interview Questions & Answers
  8. Linux Interview Questions – Basic File and Directory Permissions
  9. Oracle RAC Interview Questions – Coherence and Split-Brain
  10. Networking Protocols Interview Questions and Answers

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright