{"id":32787,"date":"2021-06-09T16:13:00","date_gmt":"2021-06-09T20:13:00","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=32787"},"modified":"2021-06-09T16:13:00","modified_gmt":"2021-06-09T20:13:00","slug":"constant-literals-in-objective-c","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/06\/09\/constant-literals-in-objective-c\/","title":{"rendered":"Constant Literals in Objective-C"},"content":{"rendered":"<p><a href=\"https:\/\/blog.andrewmadsen.com\/2021\/06\/07\/constant-literals-in.html\">Andrew Madsen<\/a>:<\/p>\n<blockquote cite=\"https:\/\/blog.andrewmadsen.com\/2021\/06\/07\/constant-literals-in.html\">\n<p>In 2012, with the release of Xcode 4.4 and LLVM 4.0, Apple introduced Objective-C literals for three more common Objective-C types: NSArray, NSDictionary, and NSNumber.<\/p>\n<p>[&#8230;]<\/p>\n<p>However, unlike NSStrings, these literals were just syntactic sugar for calls to the regular alloc\/init methods at runtime, and as such they couldn&rsquo;t be used to initialize global variables.<\/p>\n<p>[&#8230;]<\/p>\n<p>Xcode 13 ships with a new major release of Clang\/LLVM, version 13. New in this release is support for constant literals for NSNumber, NSArray, and NSDictionary.<\/p>\n<p>[&#8230;]<\/p>\n<p>I take this to mean that even where these kinds of literals are not used to initialize global variables, ie. anywhere else they&rsquo;re used in your code, the compiler may optimize them into the CONST section of your binary.<\/p>\n<p>[&#8230;]<\/p>\n<p>Apple has updated the plutil command line tool included with Xcode so that it can create Objective-C source files containing constant literals from plist data.<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/06\/09\/plutil-enhanced-in-catalina\/\">plutil Enhanced in Catalina<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2013\/06\/30\/objective-c-literals-and-compatibility_alias\/\">Objective-C Literals and @compatibility_alias<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2012\/03\/21\/objective-c-literals\/\">Objective-C Literals<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Andrew Madsen: In 2012, with the release of Xcode 4.4 and LLVM 4.0, Apple introduced Objective-C literals for three more common Objective-C types: NSArray, NSDictionary, and NSNumber. [&#8230;] However, unlike NSStrings, these literals were just syntactic sugar for calls to the regular alloc\/init methods at runtime, and as such they couldn&rsquo;t be used to initialize [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2021-06-09T20:13:03Z","apple_news_api_id":"2c367608-acef-4229-85fe-270cf9d3a5c9","apple_news_api_modified_at":"2021-06-09T20:13:03Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/ALDZ2CKzvQimF_icM-dOlyQ","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[31,2078,46,30,2077,54,71],"class_list":["post-32787","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios-15","tag-languagedesign","tag-mac","tag-macos-12","tag-objective-c","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/32787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=32787"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/32787\/revisions"}],"predecessor-version":[{"id":32788,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/32787\/revisions\/32788"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=32787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=32787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=32787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}