Skip to main content

Can we use Swift’s reserved keywords as variable or constant names?

· One min read
Ace the iOS Interview
Aryaman Sharda
Sources & Resources

Main Source: 🔗 Ace the iOS Interview

Additional Sources:

Further Reading:

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.