![]() |
VOOZH | about |
Every programming language has some set of reserved words that are used for some internal process or represent some predefined actions such words are known as keywords or reserve words. You are not allowed to use these reserved words as a variable name, constant name, or any other identifier. But if you want to want to use keywords as identifiers then you have to use the backtick (`) before and after the specified keyword. For example, a struct is a keyword it is not an identifier but `struct` is a valid identifier. backtick does not work with identifiers like `a` and a both are the same. In Swift, keywords are categorized in four categories according to their usage:
Following are the keywords used in the declaration:
| associatedtype | class | deinit | enum | extension | fileprivate | func | import |
| init | inout | internal | let | open | operator | private | precedencegroup |
| protocol | public | rethrows | static | struct | subscript | typealias | var |
Example:
Output:
Employee Name: Mohit Employee ID: 1234
Following are the keywords used in the statement:
| break | case | catch | continue | default | defer | |
| do | else | fallthrough | for | guard | if | |
| in | repeat | return | throw | switch | where | while |
Example:
Output:
Senior Citizen
Following are the keywords used in the expression and type:
| Any | as | catch | false | is |
| nil | rethrows | self | Self | super |
| throw | throws | true | try | |
Example:
Output:
Hello! My name is Govind I m working in the HR department
In Swift language, some keywords are used in a specific context, and outside the context of the grammar, they are allowed to use as identifiers. Following are the keywords used in the specific context:
| associativity | convenience | didSet | dynamic | final | get | indirect | infix | lazy |
| left | mutating | none | nonmutating | optional | override | postfix | precedence | prefix |
| Protocol | required | right | set | some | Type | unowned | weak | willSet |
Example:
Output:
Mohit
Following are the keywords that begin with the number sign(#):
| #available | #colorLiteral | #column | #dsohandle | #elseif | #else | #endif |
| #error | #fileID | #fileLiteral | #filePath | #file | #function | #if |
| #imageLiteral | #keyPath | #line | #selector | #sourceLocation | #warning | |
Example:
Output:
I am the GeeksforGeeks()
In Swift, underscore(_) keyword is used in patterns. Suppose you want to print a pattern 14 times then you can use this keyword.
Example:
Output:
GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks