Objective-C keywords

Here in this section we will know about the keywords used in objective-C language.

Objective-C keywords


Here in this section we will know about the keywords used in objective-C language. Objective-C is a superset of C language, so program written in c and C++ should compile as objective-c. It provides some additional keywords, to avoid conflict with keywords in other language it uses [email protected]? at the beginning of keyword. These keyword are called Compiler Directives.


Directives used to declare and define classes, categories and protocols:

Directive Definition
@interface used to declare of class or interface.
@implementation used to define a class or category.
@protocol used to declare a formal protocol.
@end ends the declaration, definition, category or protocol.

Directive used to specify the visibility of the instance. Default is @protected.

Directive Definition
@private Limits the scope of an instance variable to the class that declares it.
@protected Limits instance variable scope to declaring and inheriting classes.
@public Removes restrictions on the scope of instance variables.

Exception handling directives.

Directive Definition
@try Defines a block within which exceptions can be thrown.
@throw Throws an exception object.
@catch Catches an exception thrown within the preceding @try block.
@finally A block of code that is executed whether exceptions were thrown or not in a @try block.

Directive used for particular purpose.

Directive Definition
@class Declares the names of classes defined elsewhere.
@selector(method_name) It returns the compiled selector that identifies method_name.
@protocol(protocol_name) Returns the protocol_name protocol (an instance of the Protocol class). (@protocol is also valid without (protocol_name) for forward
@encode(type_spec) Yields a character string that encodes the type structure of type_spec.
@"string" Defines a constant NSString object in the current module and
initializes the object with the specified 7-bit ASCII-encoded string.
@"string1" @"string2" ...
Defines a constant NSString object in the currentmodule. The string
created is the result of concatenating the strings specified in the two
@synchronized() Defines a block of code that must be executed only by one thread
at a time.

Some keywords of Objective-C are not reserved outside. These are?..

in out inout bycopy
byref oneway    

Keyword for memory management in Objective-C 
These are looking as keywords but infact these are methods of root class NSObject.

alloc retain release autorelease

Some other keywords:

1.  bool
is a keyword used in objective-C but its value is here YES or NO. In C and C++ it has value either TRUE or FALSE.
2. 'super' and 'self' can be treated as keywords but self is a hidden parameter to each method and super gives the instructions to the compiler that how to use self differently.

Preprocessor Directives
The preprocessor directives are special notations:

Directive Definition
// This is used to comment a single line.
#import  Like C and C++ it is used to include a file but it doesn't include more than once.

Share on Google+Share on Google+

Objective-C keywords

Posted on: May 24, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Objective-C keywords   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
Rajan kumar
April 15, 2011
c languages

Objectives of the keywords
September 2, 2011
Example code

Hi ... I think you have a nice site listing the various keywords. But I wonder is there some additional site like explaining these more in detail..(referring to some tutorials with example code on how you actually implement these in the code)? Would be really thankful for this...
June 13, 2012
Objective C

I am a learner of objective c. i need to be a app developer. how can i learn objective c in a simple way, another thing i do not have Mac, I am doing program using Gnu step in windows only so teach a basic steps what i Have to do for my Carrier. I'll grateful for u.