Can we use Swift’s reserved keywords as variable or constant names?
· One min read
Sources & Resources
TL/DR
Yes and it’s accomplished through the use of backticks.
If you want to use a reserved keyword, for example as a case
in an enum
, you can just add backticks around the reserved keyword:
enum MembershipType {
case `default`
case premium
case trial
}
// Free to use MembershipType.default now
Otherwise, without the backticks, we’d have a compilation issue.