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.

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 wordRendered identifier
associatedtypeassociatedtype_
classclass_
deinitdeinit_
enumenum_
extensionextension_
fileprivatefileprivate_
funcfunc_
importimport_
initinit_
inoutinout_
internalinternal_
letlet_
openopen_
operatoroperator_
privateprivate_
protocolprotocol_
publicpublic_
rethrowsrethrows_
staticstatic_
structstruct_
subscriptsubscript_
typealiastypealias_
varvar_
breakbreak_
casecase_
continuecontinue_
defaultdefault_
deferdefer_
dodo_
elseelse_
fallthroughfallthrough_
forfor_
guardguard_
ifif_
inin_
repeatrepeat_
returnreturn_
switchswitch_
wherewhere_
whilewhile_
asas_
catchcatch_
falsefalse_
isis_
nilnil_
selfself_
SelfSelf_
supersuper_
throwthrow_
throwsthrows_
truetrue_
trytry_
AnyAny_