<p>I'm learning objective-c and keep bumping into the @ symbol. It is used in different scenarios, for example at the start of a string or to synthesise accessor methods. </p>

<p>What's does the @ symbol mean in objective-c?</p>

[{'answer_id': 25755, 'author': 'thelsdj', 'author_id': 163, 'author_profile': 'https://Stackoverflow.com/users/163', 'pm_score': 6, 'selected': False, 'text': '<p>From <a href="http://guides.macrumors.com/Objective-C_Tutorial#The_.40_symbol" rel="noreferrer">Objective-C Tutorial: The @ Symbol</a>, the reason it is on the front of various keywords:</p>\n\n<blockquote>\n  <p>Using @ should make it easier to bolt an Objective-C compiler on to an existing C compiler. Because the @ isn\'t valid in any context in C except a string literal, the tokenizer (an early and simple step in the compiler) could be modified to simply look for the @ character outside of a string constant (the tokenizer understands string literals, so it is in a position to distinguish this). When @ is encountered the tokenizer would put the rest of the compiler in "Objective-C mode." (The Objective-C parser would be responsible for returning the compiler back to regular C mode when it detects the end of the Objective-C code). </p>\n</blockquote>\n\n<p>Also when seen in front of a string literal, it makes an NSString rather than a \'char *\' in C.</p>\n'}, {'answer_id': 25784, 'author': 'Chris Hanson', 'author_id': 714, 'author_profile': 'https://Stackoverflow.com/users/714', 'pm_score': 8, 'selected': True, 'text': '<p>The <code>@</code> 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.</p>\n\n<p>Thus with very few exceptions, any time you see <code>@</code> in some Objective-C code, you\'re looking at Objective-C constructs rather than C or C++ constructs.</p>\n\n<p>The major exceptions are <code>id</code>, <code>Class</code>, <code>nil</code>, and <code>Nil</code>, which are generally treated as language keywords even though they may also have a <code>typedef</code> or <code>#define</code> behind them.  For example, the compiler actually does treat <code>id</code> 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.</p>\n\n<p>Other exceptions are <code>in</code>, <code>out</code>, <code>inout</code>, <code>oneway</code>, <code>byref</code>, and <code>bycopy</code>; 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 <code>@property</code> declarations, <code>copy</code>, <code>retain</code>, <code>assign</code>, <code>readonly</code>, <code>readwrite</code>, <code>nonatomic</code>, <code>getter</code>, and <code>setter</code>; those are only valid within the attribute section of a <code>@property</code> declaration.</p>\n'}, {'answer_id': 433089, 'author': 'Van Nguyen', 'author_id': 53894, 'author_profile': 'https://Stackoverflow.com/users/53894', 'pm_score': 5, 'selected': False, 'text': '<p>From <a href="http://guides.macrumors.com/Objective-C_Tutorial#The_.40_symbol" rel="noreferrer">Macrumors: Objective-C Tutorial</a>, when in front of string literal:</p>\n\n<blockquote>\n  <p>There are also @"" NSString literals. It is essentially shorthand for NSString\'s +stringWithUTF8String method.</p>\n</blockquote>\n\n<p>The @ also adds unicode support to C strings.</p>\n'}, {'answer_id': 9107765, 'author': 'pabloelustondo', 'author_id': 1173878, 'author_profile': 'https://Stackoverflow.com/users/1173878', 'pm_score': 4, 'selected': False, 'text': '<p>From the <a href="https://developer.apple.com/library/mac/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/_index.html">manual</a>:</p>\n\n<blockquote>\n  <p>Objective-C frameworks typically do not use C-style strings. Instead,\n  they pass strings around as NSString objects.</p>\n  \n  <p>The NSString class provides an object wrapper for strings that has all\n  of the advantages you would expect, including built-in memory\n  management for storing arbitrary-length strings, support for Unicode,\n  printf-style formatting utilities, and more. Because such strings are\n  used commonly though, Objective-C provides a shorthand notation for\n  creating NSString objects from constant values. To use this shorthand,\n  all you have to do is precede a normal, double-quoted string with the\n  @ symbol, as shown in the following examples:</p>\n\n<pre><code>NSString *myString = @"My String\\n";\nNSString *anotherString = [NSString stringWithFormat:@"%d %@", 1, @"String"];\n</code></pre>\n</blockquote>\n'}, {'answer_id': 73092408, 'author': 'Carl G', 'author_id': 39396, 'author_profile': 'https://Stackoverflow.com/users/39396', 'pm_score': 1, 'selected': False, 'text': '<p>As other answers have noted, the <code>@</code> symbol was convenient for adding Objective-C\'s superset of functionality to C because <code>@</code> is not used syntactically by C.</p>\n<p>As to what it represents, that depends on the context in which it is used. The uses fall roughly into two categories (keywords and literals), and I\'ve summarized the uses I could find below.</p>\n<p>I wrote most of this before finding <a href="https://nshipster.com/at-compiler-directives/" rel="nofollow noreferrer">NSHipster\'s great summary</a>. Here\'s another less thorough <a href="https://kapeli.com/cheat_sheets/Objective-C_@Compiler_Directives.docset/Contents/Resources/Documents/index" rel="nofollow noreferrer">cheat sheet</a>. (Both of those sources call things prefixed with <code>@</code> &quot;compiler directives&quot;, but I thought compiler directives were things like <code>#define</code>, <code>#ifdef</code>, etc. If someone could weigh in on the correct terminology, I\'d appreciate it.)</p>\n<h1>Objective-C Keywords</h1>\n<p><code>@</code> prefixes many Objective-C keywords:</p>\n<ul>\n<li><a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/DefiningClasses/DefiningClasses.html#//apple_ref/doc/uid/TP40011210-CH3-SW5" rel="nofollow noreferrer"><code>@interface</code></a>: declares the methods and properties associated with a class</li>\n<li><a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/DefiningClasses/DefiningClasses.html#//apple_ref/doc/uid/TP40011210-CH3-SW14" rel="nofollow noreferrer"><code>@implementation</code></a>: implements a class\'s declarations from <code>@interface</code></li>\n<li><a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithProtocols/WorkingwithProtocols.html" rel="nofollow noreferrer"><code>@protocol</code>/<code>@optional</code>/<code>@required</code></a>: declares methods and properties that are independent of any specific class.</li>\n<li><a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocDefiningClasses.html#//apple_ref/doc/uid/TP30001163-CH12-TPXREF124" rel="nofollow noreferrer"><code>@class</code></a>: forward declaration of a class</li>\n<li><a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html#//apple_ref/doc/uid/TP40011210-CH5-SW4" rel="nofollow noreferrer"><code>@property</code>/<code>@synthesize</code>/<code>@dynamic</code></a>: declare properties in an <code>@interface</code></li>\n<li><a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/ErrorHandling/ErrorHandling.html#//apple_ref/doc/uid/TP40011210-CH9-SW1" rel="nofollow noreferrer"><code>@try</code>/<code>@throw</code>/<code>@catch</code>/<code>@finally</code></a>: exception handling</li>\n<li><code>@end</code>: closes <code>@interface</code>, <code>@implementation</code>, and <code>@protocol</code>.</li>\n<li><code>@encode</code>: returns a C string that encodes the internal representation of a given type</li>\n<li><code>@synchronized</code>: ensures parallel execution exclusivity</li>\n<li><code>@selector</code>/<code>@protocol</code>: return <code>SEL</code> or protocol pointers with a specified name</li>\n<li><code>@defs</code>: I\'m not really sure; it appears to import Objective-C class properties into a <code>struct</code>. NSHipster\'s page says it does not exist in modern Objective-C.</li>\n<li><code>@public</code>/<code>@package</code>/<code>@protected</code>/<code>@private</code>: access modifiers</li>\n<li><code>@available</code>: checks <a href="https://developer.apple.com/documentation/swift/marking-api-availability-in-objective-c" rel="nofollow noreferrer">API availability</a>.</li>\n<li><a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html" rel="nofollow noreferrer"><code>@autoreleasepool</code></a>: creates a new autorelease scope. Any objects that received an <code>autorelease</code> in the block will receive a <code>release</code> after exiting the block (and not before.)</li>\n</ul>\n<h1>Objective-C Literals</h1>\n<p><code>@</code> creates <a href="https://clang.llvm.org/docs/ObjectiveCLiterals.html" rel="nofollow noreferrer">Objective-C literals</a>:</p>\n<ul>\n<li><p><code>@...</code>: <a href="https://clang.llvm.org/docs/ObjectiveCLiterals.html#nsnumber-literals" rel="nofollow noreferrer">NSNumber literal</a></p>\n<pre><code>NSNumber *fortyTwo = @42;             // equivalent to [NSNumber numberWithInt:42]\nNSNumber *yesNumber = @YES;           // equivalent to [NSNumber numberWithBool:YES]\n</code></pre>\n</li>\n<li><p><code>@(...)</code>: <a href="https://clang.llvm.org/docs/ObjectiveCLiterals.html#boxed-expressions" rel="nofollow noreferrer">Boxed expressions</a></p>\n<pre><code>// numbers.\nNSNumber *piOverTwo = @(M_PI / 2);        // [NSNumber numberWithDouble:(M_PI / 2)]\n// strings.\nNSString *path = @(getenv(&quot;PATH&quot;));       // [NSString stringWithUTF8String:(getenv(&quot;PATH&quot;))]\n// structs.\nNSValue *center = @(view.center);         // Point p = view.center;\n                                          // [NSValue valueWithBytes:&amp;p objCType:@encode(Point)];\n</code></pre>\n</li>\n<li><p><code>@&quot;...&quot;</code>: <a href="https://clang.llvm.org/docs/ObjectiveCLiterals.html#boxed-c-strings" rel="nofollow noreferrer">Boxed C strings</a></p>\n</li>\n<li><p><code>@[]</code>/<code>@{}</code>: <a href="https://clang.llvm.org/docs/ObjectiveCLiterals.html#boxed-c-strings" rel="nofollow noreferrer">Container literals</a></p>\n<pre><code>NSArray *array = @[ @&quot;Hello&quot;, NSApp, [NSNumber numberWithInt:42] ];\nNSDictionary *dictionary = @{\n  @&quot;name&quot; : NSUserName(),\n  @&quot;date&quot; : [NSDate date],\n  @&quot;processInfo&quot; : [NSProcessInfo processInfo]\n};\n</code></pre>\n</li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/25749', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2799/']