What does the Objective-C @ Symbol Mean?

I’m trying to get into iPhone development and I’m also going though the Mac Hacker’s Handbook. If you start looking at Objective-C, the superset of C that Apple uses, you’ll notice the @ symbol. It warped my mind to see new symbols in C, but here’s some basic info:

The @ character isn’t used in C or C++ identifiers, so it’s used to introduce Objective-C language keywords in a way that won’t conflict with the other languages’ keywords. This enables the “Objective” part of the language to freely intermix with the C or C++ part.

Thus with very few exceptions, any time you see @ in some Objective-C code, you’re looking at Objective-C constructs rather than C or C++ constructs.

The major exceptions are id, Class, nil, and Nil, which are generally treated as language keywords even though they may also have a typedef or #define behind them. For example, the compiler actually does treat id specially in terms of the pointer type conversion rules it applies to declarations, as well as to the decision of whether to generate GC write barriers.

Other exceptions are in, out, inout, oneway, byref, and bycopy; these are used as storage class annotations on method parameter and return types to make Distributed Objects more efficient. (They become part of the method signature available from the runtime, which DO can look at to determine how to best serialize a transaction.) There are also the attributes within @property declarations, copy, retain, assign, readonly, readwrite, nonatomic, getter, and setter; those are only valid within the attribute section of a @property declaration.

from: http://stackoverflow.com/questions/25749/what-does-the-symbol-represent-in-objective-c

Also you should note that the dash ‘-’ character indicates a class method.

Leave a Reply

You must be logged in to post a comment.