> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/features/global-variables.md).

# Global Variables

{% tabs %}
{% tab title="code" %}

```swift
// excerpted from Swift Tutorials
var landmarks: [Landmark] = load("landmarkData.json")

// excerpted from 彼得潘
var grade = 0
```

{% endtab %}

{% tab title="📗 參考" %}

* 彼得潘 ⟩ [Swift 的 global variable / constant](https://medium.com/彼得潘的-swift-ios-app-開發問題解答集/swift-的-global-variable-constant-全域變數-常數-726646e3552d)
* Swift Tutorials ⟩ [Create a Landmark Model](https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation#Create-a-Landmark-Model)
  {% endtab %}

{% tab title="📘 手冊" %}

* Swift ⟩ [Global and Local Variables](https://docs.swift.org/swift-book/LanguageGuide/Properties.html#ID263)
  {% endtab %}

{% tab title="🗣 討論" %}

* [How to create a global variable?](https://stackoverflow.com/a/26195727/5409815)
  {% endtab %}
  {% endtabs %}

{% hint style="info" %}

* 任何檔案皆可存取 global variable。
* global variable 寫在哪個檔案都可以。
* **Global** constants and variables are always computed **lazily**.

  :point\_right: [Lazy Stored Properties](https://docs.swift.org/swift-book/LanguageGuide/Properties.html#ID257)
* **Global** variables are defined **outside** of any **function**, **method**, **closure**, or **type** context.
  {% endhint %}
