Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Compiler Directives

Directives to the compiler begin with “@”. The following directives are used to declare and define classes, categories, and protocols:

Directive

Definition

@interface

Begins the declaration of a class or category interface.

@implementation

Begins the definition of a class or category.

@protocol

Begins the declaration of a formal protocol.

@end

Ends the declaration/definition of a class, category, or protocol.

The following mutually exclusive directives specify the visibility of instance variables:

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.

The default is @protected.

These directives support exception handling:

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

Defines a block of code that is executed whether exceptions were thrown or not in a preceding @try block.

In addition, there are directives for these particular purposes:

Directive

Definition

@class

Declares the names of classes defined elsewhere.

@selector(method_name)

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 declarations.)

@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" ... @"stringN"

Defines a constant NSString object in the current module. The string created is the result of concatenating the strings specified in the two directives.

@synchronized()

Defines a block of code that must be executed only by one thread at a time.



< Previous PageNext Page > Hide TOC


Last updated: 2008-02-05




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice