Skip to content

Add CasePathable.case#244

Merged
stephencelis merged 2 commits into
mainfrom
case-property
Jun 26, 2026
Merged

Add CasePathable.case#244
stephencelis merged 2 commits into
mainfrom
case-property

Conversation

@stephencelis

Copy link
Copy Markdown
Member

With the introduction of CasePathReflectable we could look up an enum's case statically:

let enum = Foo.bar
Enum.allCasePaths[enum]  // \.bar

Let's make things a little more ergonomic by introducing a case property.

As a keyword, case is unlikely to conflict with other properties, and it makes enums a little more usable where key path APIs are involved:

.sheet(item: $enum, id: \.case) { enum in
  // ...
}

With the introduction of `CasePathReflectable` we could look up an enum's case statically:

```swift
let enum = Foo.bar
Enum.allCasePaths[enum]  // \.bar
```

Let's make things a little more ergonomic by introducing a `case` property.

As a keyword, `case` is unlikely to conflict with other properties, and it makes enums a little more
usable where key path APIs are involved:

```swift
.sheet(item: $enum, id: \.case) { enum in
  // ...
}
```
@stephencelis stephencelis requested a review from mbrandonw June 25, 2026 17:20
@stephencelis stephencelis merged commit 98894e0 into main Jun 26, 2026
4 checks passed
@stephencelis stephencelis deleted the case-property branch June 26, 2026 17:23
bok- pushed a commit to bok-/swift-case-paths-with-traits that referenced this pull request Jul 12, 2026
* Add `CasePathable.case`

With the introduction of `CasePathReflectable` we could look up an enum's case statically:

```swift
let enum = Foo.bar
Enum.allCasePaths[enum]  // \.bar
```

Let's make things a little more ergonomic by introducing a `case` property.

As a keyword, `case` is unlikely to conflict with other properties, and it makes enums a little more
usable where key path APIs are involved:

```swift
.sheet(item: $enum, id: \.case) { enum in
  // ...
}
```

* wip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants