# declaration

[Swift](https://lochiwei.gitbook.io/ios/swift) ⟩ [concept](https://lochiwei.gitbook.io/ios/master/term) ⟩ declaration

{% hint style="success" %}
defines <mark style="color:yellow;">**new variables or types**</mark>.
{% endhint %}

{% tabs %}
{% tab title="🔴 主題" %}

* [func](https://lochiwei.gitbook.io/ios/swift/type/category/basic/func "mention")
* [class](https://lochiwei.gitbook.io/ios/swift/type/category/basic/class "mention")
* [enum](https://lochiwei.gitbook.io/ios/swift/type/category/basic/enum "mention")
* struct 🚧
* [protocol](https://lochiwei.gitbook.io/ios/swift/type/category/protocol "mention")
* ... 🚧
  {% endtab %}

{% tab title="⭐️ 重點" %}
{% hint style="success" %} <mark style="color:orange;">**use cases**</mark>&#x20;

* define [func](https://lochiwei.gitbook.io/ios/swift/type/category/basic/func "mention")s and **methods** 🚧
* define **variables** and **constants**
* define [enum](https://lochiwei.gitbook.io/ios/swift/type/category/basic/enum "mention"), <mark style="color:blue;">**struct**</mark>  🚧, [class](https://lochiwei.gitbook.io/ios/swift/type/category/basic/class "mention"), [protocol](https://lochiwei.gitbook.io/ios/swift/type/category/protocol "mention")
* <mark style="color:yellow;">**extend**</mark> the behavior of an <mark style="color:yellow;">**existing**</mark>**&#x20;**<mark style="color:orange;">**named**</mark>**&#x20;**<mark style="color:yellow;">**type**</mark>
* <mark style="color:yellow;">**import**</mark> symbols into your program that are declared elsewhere.
  {% endhint %}

{% hint style="info" %}
GRAMMAR OF A DECLARATION

* declaration → [import-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_import-declaration)
* declaration → [constant-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_constant-declaration)
* declaration → [variable-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_variable-declaration)
* declaration → [typealias-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_typealias-declaration)
* declaration → [function-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_function-declaration)
* declaration → [enum-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_enum-declaration)
* declaration → [struct-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_struct-declaration)
* declaration → [class-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_class-declaration)
* declaration → [actor-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_actor-declaration)
* declaration → [protocol-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_protocol-declaration)
* declaration → [initializer-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_initializer-declaration)
* declaration → [deinitializer-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_deinitializer-declaration)
* declaration → [extension-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_extension-declaration)
* declaration → [subscript-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_subscript-declaration)
* declaration → [operator-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_operator-declaration)
* declaration → [precedence-group-declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_precedence-group-declaration)
* declarations → [declaration](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_declaration) [declarations](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#grammar_declarations) opt
  {% endhint %}

{% hint style="info" %}
In Swift, most <mark style="color:purple;">**declarations**</mark> are also <mark style="color:yellow;">**definitions**</mark> in the sense that they’re implemented or <mark style="color:yellow;">**initialized**</mark> **at the&#x20;**<mark style="color:yellow;">**same time**</mark>**&#x20;they’re&#x20;**<mark style="color:yellow;">**declared**</mark>, .... the distinction <mark style="color:red;">**isn’t**</mark>**&#x20;**<mark style="color:yellow;">**that important**</mark> in Swift, the term <mark style="color:purple;">**declaration**</mark> covers both <mark style="color:orange;">declarations</mark> and <mark style="color:orange;">definitions</mark>.
{% endhint %}
{% endtab %}

{% tab title="👥 相關" %}

* <mark style="color:purple;">**declaration**</mark> is a [](https://lochiwei.gitbook.io/ios/swift/statement/simple "mention").
  {% endtab %}

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

* [ ] [Declarations](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: 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/swift/statement/simple/declaration.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.
