asker

heapify-deactivated20130709 asked: Why do Strings in Objective-C have to be preceded with an @?

Simple: because if you left it off, it wouldn’t be an NSString*. It’d be a char *. Any time you see the @ symbol in Objective-C code, you can know that it’s so that the compiler can do something special there that C doesn’t natively support.

So with that in mind, we have:

  • @catch: declare a scope for catching a thrown execution
  • @class: forward declare a class
  • @compatibility_alias: specify an alias for a class name
  • @dynamic: specify that property accessors will by dynamically implemented at runtime
  • @encode: ask for a character array representing the type of a variable
  • @end: close an interface declaration or an implementation block
  • @finally: declare code that will be executed after an @try and/or @catch block execute
  • @implementation: implement a class definition
  • @interface: define a class API (also used for categories and class extensions)
  • @optional: declare the optional nature of protocol methods
  • @package: declare the scope of ivars
  • @private: declare the scope of ivars
  • @property: declare a class property
  • @protected: declare the scope of ivars
  • @protocol: declare a list of methods that conforming objects might implement
  • @public: declare the scope of ivars
  • @required: declare the required nature of protocol methods
  • @selector: declare the the stuff that immediately follows in the parentheses is a method name
  • @synchronized: declare a section of code that is atomic
  • @synthesize: direct the compiler to generate accessor methods for properties (that you haven’t implemented yourself)
  • @throw: throw an NSException
  • @try: begin a block in which an exception might be thrown
  • @"": declare a constant string

That’s all I can remember off the top of my head. I’m sure I’ve forgotten one or two. A more complete list (with better explanations) can be found in the documentation.

  1. funwithobjc posted this
Short URL for this post: http://tmblr.co/Zt522y3FSXwK
blog comments powered by Disqus