> 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 %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/ios/features/global-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
