Swift Tutorial
Swift Data Types
Swift Control Flow
Swift Functions
Swift Collections
Swift OOPs
Swift Additional Topics
Swift, like all programming languages, has a set of keywords—these are reserved words that have special meaning and cannot be used as identifiers (like variable or function names) unless enclosed in backticks (`).
Here's a list of some of the primary keywords in Swift. This list isn't exhaustive, and Swift may introduce new keywords in future versions.
Declaration Keywords: class
, deinit
, enum
, extension
, func
, import
, init
, inout
, let
, operator
, protocol
, struct
, subscript
, typealias
, var
Statement Keywords: break
, case
, continue
, default
, defer
, do
, else
, fallthrough
, for
, guard
, if
, in
, repeat
, return
, switch
, where
, while
Expressions and Types Keywords: as
, Any
, catch
, false
, is
, nil
, rethrows
, throw
, throws
, true
, try
Patterns Keywords: _
, case
, is
Access Control Keywords: open
, public
, internal
, fileprivate
, private
Protocol Keywords: associatedtype
, convenience
, dynamic
, final
, lazy
, mutating
, nonmutating
, optional
, override
, postfix
, prefix
, required
, static
, unowned
, weak
Others: actor
, some
, async
, await
, concurrent
When using a keyword as an identifier, you can surround it with backticks to tell the compiler to treat it as a regular identifier:
let `default` = "This is a variable named default"
However, using keywords as identifiers is discouraged unless absolutely necessary because it can make code harder to read.
It's also worth noting that Swift introduces new keywords and updates existing ones with major releases, so always refer to the official Swift documentation or language guides for the most current list.