Raw Identifiers in Swift 6.2


Greetings, traveler!

Swift 6.2 brings a subtle but powerful change to the language with SE-0451, allowing developers to use almost any characters in identifier names—by wrapping them in backticks (`). This makes your code more expressive, more readable, and in many cases, just more natural.

You can now write functions like this:

func `something special`() {
   // ...
}

`something special`()

Numeric Enum Cases

Previously, modeling enums with numeric identifiers often required awkward naming hacks like case _500 or case core450. Imagine, you need to create a design system with specific font sizes, which were marked with integer identifiers by designer. With raw identifiers, you can write:

enum FontSize {
    case `100`
    case `150`
    case `300`
    case `450`
}

Tests

One of the most practical benefits of this feature is in Swift Testing. Instead of writing your test name in camel case and repeating a description string above, your test method can simply be the description:

import Testing

@Test("Some action")
func someAction() {
    // test implementation
}

@Test
func `Some action`() {
    // test implementation
}

One Small Gotcha: Operators Alone Aren’t Allowed

A minor rule worth noting: identifiers may include operator characters like + or -, but they cannot consist of only those characters. So `value+tax` is valid, but `+` is not.