Targets · Swift · Reserved words
Reserved words
Swift keeps a set of words for its own syntax, so a program cannot use them as names. When a Program
name collides with one, the renderer appends a single underscore — class becomes
class_ — so the program keeps the name it chose and the output still compiles.
Because _ is illegal in a Program identifier, the escape can never collide with a name a
program actually chose.
Contents
How a Program becomes Swift, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.
- Introduction — what the Swift target is, and how to read the rest of this section.
- Capabilities — which high-level features are possible, built in or through a library.
- Example — a full program using every keyword, and the Swift it renders to.
- Naming considerations — how Program's dotted names are carried into Swift.
- Entry point — starting a program and mounting it as a SwiftUI app.
- Drivers — the native drivers that provide the interface, animation and network.
- Runtime — the Reactive and Context machinery the rendered code links against.
- Native modules — the hand-written Swift behind
NATIVEfunctions. - Keywords — how each of Program's keywords renders to Swift.
- Project setup — the files and commands to build and run the rendered program.
- Reserved words — the words Swift keeps for itself, and how a colliding name is escaped.
The full list
Every word Swift reserves, with the identifier a colliding Program name is escaped to. The rule is
uniform — append a single _:
| Reserved word | Rendered identifier |
|---|---|
associatedtype | associatedtype_ |
class | class_ |
deinit | deinit_ |
enum | enum_ |
extension | extension_ |
fileprivate | fileprivate_ |
func | func_ |
import | import_ |
init | init_ |
inout | inout_ |
internal | internal_ |
let | let_ |
open | open_ |
operator | operator_ |
private | private_ |
protocol | protocol_ |
public | public_ |
rethrows | rethrows_ |
static | static_ |
struct | struct_ |
subscript | subscript_ |
typealias | typealias_ |
var | var_ |
break | break_ |
case | case_ |
continue | continue_ |
default | default_ |
defer | defer_ |
do | do_ |
else | else_ |
fallthrough | fallthrough_ |
for | for_ |
guard | guard_ |
if | if_ |
in | in_ |
repeat | repeat_ |
return | return_ |
switch | switch_ |
where | where_ |
while | while_ |
as | as_ |
catch | catch_ |
false | false_ |
is | is_ |
nil | nil_ |
self | self_ |
Self | Self_ |
super | super_ |
throw | throw_ |
throws | throws_ |
true | true_ |
try | try_ |
Any | Any_ |