# Where can I get the full list of Swift keywords?

**URL:** <https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488>\
**Category:** Swift Documentation Tooling\
**Tags:** keywords\
**Created:** [April 26, 2024, 6:47pm UTC](https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488 "2024-04-26T18:47:58Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![John\_McCall](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/john_mccall/32/1351_2.png) [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Post date:** [May 20, 2024, 5:40pm UTC](https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488/21 "2024-05-20T17:40:38Z")

</div>

In general, using a list of identifiers that the compiler wants to easily recognize as a list of keywords to highlight is going to lead to bad results. The compiler sometimes has to add special cases for certain declarations, e.g. to maintain source compatibility; that doesn’t mean you should highlight them differently in an editor.

In particular, many of those identifiers are actually attribute names. You should probably have a rule for highlighting after an `@` that covers all attributes without having to recognize specific attribute names.

---

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [May 20, 2024, 7:31pm UTC](https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488/22 "2024-05-20T19:31:59Z")

</div>

> [@dima\_kozhinov](#):
>
> Yes, it is a desktop app, not written in Swift, that should be able to do syntax highlighting without installing Swift.

i don’t know the full story of your app’s architecture, but unless you have major constraints preventing you from depending on SwiftSyntax/LSP i really, strongly, suggest you work on a way to get SwiftSyntax running on the target platform, because i am skeptical that an approach that involving detecting special substrings in source text is going to be successful.

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [May 20, 2024, 9:36pm UTC](https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488/23 "2024-05-20T21:36:57Z")

</div>

I think it will cover the main 95% of cases easily, especially if to add some heuristic like highlighting after `@`, `#` and `//`, and within "strings" or /\* comments \*/. It would be quite useful even if it doesn't cover all 100% of cases.  
I'd make contextual keywords (that could result in false positives) of a different colour compared to "always" keywords, e.g. less prominent.

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [May 20, 2024, 11:33pm UTC](https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488/24 "2024-05-20T23:33:48Z")

</div>

> [@John\_McCall](#):
>
> In general, using a list of identifiers that the compiler wants to easily recognize as a list of keywords to highlight is going to lead to bad results. The compiler sometimes has to add special cases for certain declarations, e.g. to maintain source compatibility; that doesn’t mean you should highlight them differently in an editor.
> 
> In particular, many of those identifiers are actually attribute names. You should probably have a rule for highlighting after an `@` that covers all attributes without having to recognize specific attribute names.

I also feel that recognizing all keyword, including internal ones, is non-goal for a syntax highlighting engine. I would focus on making sure nested structure and delimiters are parsed correctly in all circumstances instead.

---

<div class="post-metadata">

**Author:** ![dima\_kozhinov](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dima\_kozhinov](https://forums.swift.org/u/dima_kozhinov)\
**Post date:** [May 21, 2024, 1:37pm UTC](https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488/25 "2024-05-21T13:37:47Z")

</div>

> [@Slava\_Pestov](#):
>
> recognizing all keyword, including internal ones, is non-goal

Indeed. But how do I know that a keyword is "internal"? Do you mean those keywords that start with the `_` character?

---

<div class="post-metadata">

**Author:** ![Nobody1707](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nobody1707/32/2169_2.png) [@Nobody1707](https://forums.swift.org/u/Nobody1707)\
**Post date:** [May 21, 2024, 10:22pm UTC](https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488/26 "2024-05-21T22:22:33Z")

</div>

All underscored keywords are internal. The contextual keyword `yield` is also technically internal, but `_read` and `_modify` are so useful that all three have leaked out into production code. I think that's all of them, unless there's some ancient internal keyword nobody uses anymore floating around without any underscores.

---

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [May 21, 2024, 11:52pm UTC](https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488/27 "2024-05-21T23:52:40Z")

</div>

> [@Nobody1707](#):
>
> I think that's all of them, unless there's some ancient internal keyword nobody uses anymore floating around without any underscores.

there is also `@_spi`, `@_exported`, and the ` __owned`, `__ shared`, and `__consuming` keywords. they are technically internal but the latter three keywords are so common it is hard to read certain signatures if they are not highlighted.

today, in new code, ` __owned` and `__ consuming` are mostly used to work around compiler bugs, and i imagine they will die out soon. i don’t see `__shared` going away any time soon, as it’s quite a bit more challenging to substitute `borrowing` for it.

---

<div class="post-metadata">

**Author:** ![doozMen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/doozmen/32/7803_2.png) [@doozMen](https://forums.swift.org/u/doozMen)\
**Post date:** [November 25, 2024, 9:13am UTC](https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488/28 "2024-11-25T09:13:04Z")

</div>

I was recently approached by someone who did not know Swift. But he abandoned the language just because of this discussion. Too many keywords. I found that short sighted and was unable to answer do to not enough knowledge about other languages. But however if somebody feels up to writing a comprehensive blog post about this subject it would help if it could be put on [swift.org](http://swift.org) to point criticasters too? I would be happy to help in the writing/reviewing. Anybody has ideas for this?

---

<div class="post-metadata">

**Author:** ![idrougge](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/idrougge/32/3885_2.png) [@idrougge](https://forums.swift.org/u/idrougge)\
**Post date:** [November 25, 2024, 10:17am UTC](https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488/29 "2024-11-25T10:17:45Z")

</div>

Some languages make a point out of having few reserved keywords, to the point where they instead overload keywords based on context. `static` means several different things in C/C++ depending on where they're used.

Go uses `for` for all loop constructs whereas Swift has `for`, `while` and `repeat`. That means that you can discern what kind of loop a Swift loop is at a glance whereas a Go loop requires looking closely at the full signature of `for` to see if it is an iterating one, a `while true` or `until true` one.

Go even goes as far as using _comments_ to control compilation and linking, just to avoid introducing more keywords.

Swift also has looping constructs that are defined as methods, such as `.forEach`. Those are not classified as keywords but they exist all the same, and I wouldn't call a language where `if` and `else` are method less complex than one where they are keywords — unless your goal is to construct a syntax highlighter.

[Previous page](https://forums.swift.org/t/where-can-i-get-the-full-list-of-swift-keywords/71488.md?page=1)
