{"title":"Literal Syntax for NSArray, NSDictionary & NSNumber","html_url":"https://deallocatedobjects.com/posts/new-objective-c-literal-syntax-for-nsarray-nsdictionary-nsnumber","source_url":"http://joris.kluivers.nl/blog/2012/03/13/new-objectivec-literal-syntax/","markdown_content":"I can't tell you how long I've been waiting for this.\r\n\r\nAs [Joris points out](http://joris.kluivers.nl/blog/2012/03/13/new-objectivec-literal-syntax/), it appears that Apple has [committed the necessary changes](http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/?view=log&pathrev=152137) to the LLVM project to allow LLVM to fully support the latest Objective-C language features.\r\n\r\n> Apple committed a new patch to the llvm project adding support for new Objective-C literal syntax for `NSArray`, `NSDictionary` and `NSNumber`. These have previously been documented in the Mountain Lion Xcode release notes but that was still under NDA. Now that these features have been committed to llvm I guess we’re allowed to speak about it.\r\n\r\n...and since LLVM isn't under NDA like most of the \"developer preview\" stuff, this means we can all finally discuss this stuff on our blogs!\r\n\r\nHere's a (small) taste of the great new syntax:\r\n\r\n### NSNumber\r\n\r\n``` objc\r\nNSNumber *someNumber = @31;  // [NSNumber numberWithInt:31] \r\n```\r\n\r\n### NSArray\r\n\r\n``` objc\r\n//NSArray *doctors = [NSArray arrayWithObjects:@\"Matt Smith\", @\"David Tennant\", @\"Tom Baker\", nil];\r\nNSArray *doctors = @[@\"Matt Smith\", @\"David Tennant\", @\"Tom Baker\"];\r\n```\r\n\r\n### NSDictionary\r\n\r\n``` objc\r\nNSDictionary *tweet = @{\r\n  @\"text\": @\"Hi! I'm a tweet!\",\r\n  @\"user\": @\"jakemarsh\",\r\n  @\"timestamp\": @1331664532\r\n};\r\n```","html_content":"<p>I can’t tell you how long I’ve been waiting for this.</p>\n\n<p>As <a href=\"http://joris.kluivers.nl/blog/2012/03/13/new-objectivec-literal-syntax/\">Joris points out</a>, it appears that Apple has <a href=\"http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/?view=log&amp;pathrev=152137\">committed the necessary changes</a> to the LLVM project to allow LLVM to fully support the latest Objective-C language features.</p>\n\n<blockquote>\n<p>Apple committed a new patch to the llvm project adding support for new Objective-C literal syntax for <code>NSArray</code>, <code>NSDictionary</code> and <code>NSNumber</code>. These have previously been documented in the Mountain Lion Xcode release notes but that was still under NDA. Now that these features have been committed to llvm I guess we’re allowed to speak about it.</p>\n</blockquote>\n\n<p>…and since LLVM isn’t under NDA like most of the “developer preview” stuff, this means we can all finally discuss this stuff on our blogs!</p>\n\n<p>Here’s a (small) taste of the great new syntax:</p>\n\n<h2 id=\"nsnumber\" data-level=\"3\">NSNumber</h2>\n<figure class=\"code\" data-lang=\"objective-c\"><figcaption><span class=\"lang\">Objective-C</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSNumber</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> *</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">someNumber </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> @</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">31</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;  </span><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// [NSNumber numberWithInt:31] </span></span></code></pre></figure>\n<h2 id=\"nsarray\" data-level=\"3\">NSArray</h2>\n<figure class=\"code\" data-lang=\"objective-c\"><figcaption><span class=\"lang\">Objective-C</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">//NSArray *doctors = [NSArray arrayWithObjects:@\"Matt Smith\", @\"David Tennant\", @\"Tom Baker\", nil];</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSArray</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> *</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">doctors </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> @[</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">@\"Matt Smith\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">@\"David Tennant\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">@\"Tom Baker\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">];</span></span></code></pre></figure>\n<h2 id=\"nsdictionary\" data-level=\"3\">NSDictionary</h2>\n<figure class=\"code\" data-lang=\"objective-c\"><figcaption><span class=\"lang\">Objective-C</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">NSDictionary</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> *</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">tweet </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> @{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">  @\"text\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">@\"Hi! I'm a tweet!\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">  @\"user\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">@\"jakemarsh\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">  @\"timestamp\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: @</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">1331664532</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">};</span></span></code></pre></figure>","created_at":"2013-11-16T05:10:25.570Z","updated_at":"2014-11-19T16:51:23.014Z"}