{"id":6925,"date":"2014-06-11T14:21:43","date_gmt":"2014-06-11T11:21:43","guid":{"rendered":"http:\/\/railsware.com\/blog\/?p=6925"},"modified":"2021-08-12T13:01:13","modified_gmt":"2021-08-12T10:01:13","slug":"global-variables-in-swift-are-not-variables","status":"publish","type":"post","link":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/","title":{"rendered":"Global variables in Swift are not variables"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The title sounds pretty strange, but I will explain what it means.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While playing with Swift I&#8217;ve faced weird behaviour, a feature in fact, which isn&#8217;t covered in documentation (at least I didn&#8217;t find any references!).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>UPD:<\/strong> shame on me, how could I miss this?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Global constants and variables are always computed lazily, in a similar manner to Lazy Stored Properties. Unlike lazy stored properties, global constants and variables do not need to be marked with the @lazy attribute.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Global variables are functions and their actual values instantiate on demand<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The problem<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I wanted to perform some function from different translation unit without explicit calling, and decided to try old C++ trick with global variable:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:c++ decode:true toolbar:1\">#include &lt;iostream&gt;\n\nint globalFunc() \n{\n    std::cout &lt;&lt; \"hello, world!\\n\";\n    return 42;\n}\n\nint globalVar = globalFunc();<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted lang:c++ decode:true toolbar:1\">int main(int argc, const char * argv[])\n{\n    return 0;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After compiling and running this program you&#8217;ll see &#8220;hello, world!&#8221; in the output, so I&#8217;ve tried the same trick with swift:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:1 lang:go decode:true\">import Foundation\n\nfunc globalFunc() -&gt; Int \n{\n    println(\"hello, world!\")\n    return 42\n}\n\nvar globalVar = globalFunc()<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:1 lang:go decode:true\">\/\/ currently, this file is empty<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But had no luck&#8230; This program does nothing in swift.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Explanation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">At the first glance, it looks like compiler optimisation, but what if we call this variable from debugger?<\/p>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:2 lang:default decode:true\">(lldb) po globalVar\nhello, world!\n42\n\n(lldb)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It works. Weird. But it works!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ok, so let&#8217;s access to this variable from <code class=\"\" data-line=\"\">main.swift<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:1 lang:go decode:true\">var localOne = globalVar<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It works as well, so variable instantiates at the first call. But how it works and why?<br>To understand how it works we definitely should dive deeper into the executable. Usually I&#8217;m using LLVM IR for such purposes, but this time I decided to use <a title=\"Hopper\" href=\"http:\/\/www.hopperapp.com\" target=\"_blank\" rel=\"noopener\">Hopper<\/a>, &#8217;cause it has a very useful feature: &#8216;Show pseudocode&#8217;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After opening the executable via Hopper you may see that app also has function <code class=\"\" data-line=\"\">main<\/code> as an entry point, this function calls <code class=\"\" data-line=\"\">_top_level_code<\/code>, which consists of <code class=\"\" data-line=\"\">main.swift<\/code>. Let&#8217;s look at pseudocode of <code class=\"\" data-line=\"\">_top_level_code<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:1 lang:js decode:true\">function _top_level_code {\n    rax = __TF10swift_testa9globalVarSi();\n    rax = *rax;\n    *__Tv10swift_test8localOneSi = rax;\n    return rax;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and get rid of &#8216;garbage&#8217;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:1 lang:js decode:true\">v_localOne = F_globalVar();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of direct access to variable, it calls respective function; let&#8217;s look at it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:1 lang:js decode:true\">function __TF10swift_testa9globalVarSi {\n    swift_once(_globalinit_token0, _globalinit_func0, 0x0);\n    return __Tv10swift_test9globalVarSi;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">it calls another function <code class=\"\" data-line=\"\">swift_once<\/code> and returns actual variable <code class=\"\" data-line=\"\">globalVar<\/code>. Ok, let&#8217;s go deeper, currently we&#8217;re interested in the second parameter: <code class=\"\" data-line=\"\">_globalinit_func0<\/code>, it&#8217;s also function:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:1 lang:js decode:true\">function _globalinit_func0 {\n    rax = __TF10swift_test10globalFuncFT_Si();\n    *__Tv10swift_test9globalVarSi = rax;\n    return rax;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Caught it! Finally, we&#8217;ve found function which does exactly what we want:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:1 lang:go decode:true\">v_globalVar = F_globalFunc()<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Any global variable in Swift is being replaced with respective function call that initializes this variable on demand<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s wrap up our small research!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This code<\/p>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:1 lang:go decode:true\">func globalFunc() -&gt; Int\n{\n    println(\"hello, world\")\n    return 42\n}\n\nvar globalVar = globalFunc()<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:1 lang:go decode:true\">var localOne = globalVar<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">translates into this one:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:1 lang:go decode:true\">func F_globalFunc() -&gt; Int\n{\n    println(\"hello, world\")\n    return 42\n}\n\nvar v_globalVar_init = 0\nvar v_globalVar = zero\n\nfunc F_globalVar_init()\n{\n    v_globalVar_init = 1\n    v_globalVar = F_globalFunc()\n}\n\nfunc F_globalVar() \n{\n    if (v_globalVar_init == 0) {\n        F_globalVar_init()\n    }\n    return v_globalVar\n}\n\n\/\/ ....\nvar v_localOne = F_globalVar()<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So, now this behaviour is clear, but question &#8216;why such a decision was made?&#8217; is still open.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Happy hacking, guys, and be careful!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The title sounds pretty strange, but I will explain what it means. While playing with Swift I&#8217;ve faced weird behaviour, a feature in fact, which isn&#8217;t covered in documentation (at least I didn&#8217;t find any references!). UPD: shame on me, how could I miss this? Global constants and variables are always computed lazily, in a&#8230;<\/p>\n","protected":false},"author":55,"featured_media":9454,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[3],"tags":[],"coauthors":["AlexDenisov"],"class_list":["post-6925","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"Explaination of how global variables work in swift\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"AlexDenisov\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"| Blog on Engineering, Product Management, Transparency, Culture and many more...\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Global variables in Swift are not variables | Railsware Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Explaination of how global variables work in swift\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/Global-variables-in-Swift.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/Global-variables-in-Swift.png\" \/>\n\t\t<meta property=\"og:image:width\" content=\"360\" \/>\n\t\t<meta property=\"og:image:height\" content=\"360\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2014-06-11T11:21:43+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2021-08-12T10:01:13+00:00\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#article\",\"name\":\"Global variables in Swift are not variables | Railsware Blog\",\"headline\":\"Global variables in Swift are not variables\",\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/alexey-denisov\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/Global-variables-in-Swift.png\",\"width\":360,\"height\":360,\"caption\":\"Global variables in Swift are not variables\"},\"datePublished\":\"2014-06-11T14:21:43+03:00\",\"dateModified\":\"2021-08-12T13:01:13+03:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#webpage\"},\"articleSection\":\"Engineering\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"position\":2,\"name\":\"Engineering\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#listItem\",\"name\":\"Global variables in Swift are not variables\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#listItem\",\"position\":3,\"name\":\"Global variables in Swift are not variables\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/Logo-circle.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#organizationLogo\",\"width\":3137,\"height\":1054,\"caption\":\"Railsware logo\"},\"image\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#organizationLogo\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/alexey-denisov\\\/#author\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/alexey-denisov\\\/\",\"name\":\"AlexDenisov\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#authorImage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/author-image-default-96x96.jpg\",\"width\":96,\"height\":96,\"caption\":\"AlexDenisov\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#webpage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/\",\"name\":\"Global variables in Swift are not variables | Railsware Blog\",\"description\":\"Explaination of how global variables work in swift\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/alexey-denisov\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/alexey-denisov\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/Global-variables-in-Swift.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#mainImage\",\"width\":360,\"height\":360,\"caption\":\"Global variables in Swift are not variables\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/global-variables-in-swift-are-not-variables\\\/#mainImage\"},\"datePublished\":\"2014-06-11T14:21:43+03:00\",\"dateModified\":\"2021-08-12T13:01:13+03:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Global variables in Swift are not variables | Railsware Blog","description":"Explaination of how global variables work in swift","canonical_url":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#article","name":"Global variables in Swift are not variables | Railsware Blog","headline":"Global variables in Swift are not variables","author":{"@id":"https:\/\/railsware.com\/blog\/author\/alexey-denisov\/#author"},"publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/Global-variables-in-Swift.png","width":360,"height":360,"caption":"Global variables in Swift are not variables"},"datePublished":"2014-06-11T14:21:43+03:00","dateModified":"2021-08-12T13:01:13+03:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#webpage"},"isPartOf":{"@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#webpage"},"articleSection":"Engineering"},{"@type":"BreadcrumbList","@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/railsware.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","position":2,"name":"Engineering","item":"https:\/\/railsware.com\/blog\/category\/development\/","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#listItem","name":"Global variables in Swift are not variables"},"previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#listItem","position":3,"name":"Global variables in Swift are not variables","previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}}]},{"@type":"Organization","@id":"https:\/\/railsware.com\/blog\/#organization","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","url":"https:\/\/railsware.com\/blog\/","logo":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2020\/11\/Logo-circle.png","@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#organizationLogo","width":3137,"height":1054,"caption":"Railsware logo"},"image":{"@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#organizationLogo"}},{"@type":"Person","@id":"https:\/\/railsware.com\/blog\/author\/alexey-denisov\/#author","url":"https:\/\/railsware.com\/blog\/author\/alexey-denisov\/","name":"AlexDenisov","image":{"@type":"ImageObject","@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#authorImage","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2021\/06\/author-image-default-96x96.jpg","width":96,"height":96,"caption":"AlexDenisov"}},{"@type":"WebPage","@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#webpage","url":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/","name":"Global variables in Swift are not variables | Railsware Blog","description":"Explaination of how global variables work in swift","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/railsware.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#breadcrumblist"},"author":{"@id":"https:\/\/railsware.com\/blog\/author\/alexey-denisov\/#author"},"creator":{"@id":"https:\/\/railsware.com\/blog\/author\/alexey-denisov\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/Global-variables-in-Swift.png","@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#mainImage","width":360,"height":360,"caption":"Global variables in Swift are not variables"},"primaryImageOfPage":{"@id":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/#mainImage"},"datePublished":"2014-06-11T14:21:43+03:00","dateModified":"2021-08-12T13:01:13+03:00"},{"@type":"WebSite","@id":"https:\/\/railsware.com\/blog\/#website","url":"https:\/\/railsware.com\/blog\/","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","inLanguage":"en-US","publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"| Blog on Engineering, Product Management, Transparency, Culture and many more...","og:type":"article","og:title":"Global variables in Swift are not variables | Railsware Blog","og:description":"Explaination of how global variables work in swift","og:url":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/","og:image":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/Global-variables-in-Swift.png","og:image:secure_url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/Global-variables-in-Swift.png","og:image:width":360,"og:image:height":360,"article:published_time":"2014-06-11T11:21:43+00:00","article:modified_time":"2021-08-12T10:01:13+00:00"},"aioseo_meta_data":{"post_id":"6925","title":"Global variables in Swift are not variables | Railsware Blog","description":"Explaination of how global variables work in swift","keywords":[{"label":"apple swift","value":"apple swift"},{"label":"swift","value":"swift"},{"label":"iosdev","value":"iosdev"},{"label":"osxdev","value":"osxdev"}],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-6385f5b1c5434","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":{"locations":{"business":{"name":"","businessType":"","image":"","areaServed":"","urls":{"website":"","aboutPage":"","contactPage":""},"address":{"streetLine1":"","streetLine2":"","zipCode":"","city":"","state":"","country":"","addressFormat":"#streetLineOne\n#streetLineTwo\n#city, #state #zipCode"},"contact":{"email":"","phone":"","phoneFormatted":"","fax":"","faxFormatted":""},"ids":{"vat":"","tax":"","chamberOfCommerce":""},"payment":{"priceRange":"","currenciesAccepted":"","methods":""}}},"openingHours":{"useDefaults":true,"show":true,"alwaysOpen":false,"use24hFormat":false,"timezone":"","labels":{"closed":"","alwaysOpen":""},"days":{"monday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"tuesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"wednesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"thursday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"friday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"saturday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"sunday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"}}}},"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-01-04 12:44:30","updated":"2025-09-26 11:21:39","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\/category\/development\/\" title=\"Engineering\">Engineering<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tGlobal variables in Swift are not variables\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/railsware.com\/blog"},{"label":"Engineering","link":"https:\/\/railsware.com\/blog\/category\/development\/"},{"label":"Global variables in Swift are not variables","link":"https:\/\/railsware.com\/blog\/global-variables-in-swift-are-not-variables\/"}],"categories_data":[{"name":"Engineering","link":"https:\/\/railsware.com\/blog?category=development"}],"post_thumbnails":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/12\/Global-variables-in-Swift.png","article_background":"","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/6925","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/users\/55"}],"replies":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/comments?post=6925"}],"version-history":[{"count":38,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/6925\/revisions"}],"predecessor-version":[{"id":13958,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/6925\/revisions\/13958"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media\/9454"}],"wp:attachment":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media?parent=6925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/categories?post=6925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/tags?post=6925"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/coauthors?post=6925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}