# \[Pitch\] if and switch expressions

**URL:** <https://forums.swift.org/t/pitch-if-and-switch-expressions/61149>\
**Category:** Pitches\
**Created:** [October 31, 2022, 9:57pm UTC](https://forums.swift.org/t/pitch-if-and-switch-expressions/61149 "2022-10-31T21:57:39Z")\
**Posts on this page:** 1\
**Showing post:** 95

<div class="post-metadata">

**Author:** ![Paul\_Cantrell](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/paul_cantrell/32/16764_2.png) [@Paul\_Cantrell](https://forums.swift.org/u/Paul_Cantrell)\
**Post date:** [December 4, 2022, 5:51pm UTC](https://forums.swift.org/t/pitch-if-and-switch-expressions/61149/95 "2022-12-04T17:51:06Z")

</div>

Nice work, Ben and Hamish.

Is there any chance of getting [this much-upvoted suggestion](https://forums.swift.org/t/pitch-if-and-switch-expressions/61149/11) into the proposal — if not as part of what’s actually proposed for this round, then at least as a future direction?

Lack of full generality was one of the most common objections above, and doubtless will be so in formal review as well. People seem to like the solution above. It addresses all of the concerns in the [Future Directions | Full Expressions](https://github.com/apple/swift-evolution/blob/af80c4b5a7407c77dfab5cd5303bd9fde858c75f/proposals/NNNN-if-switch-expressions.md#full-expressions) section of the proposal:

```swift
// ❌ wat
for b in [true] where switch b { case true: true case false: false } {}

// ✅ meaningless, but easy enough for humans to parse visually
for b in [true] where (switch b { case true: true case false: false }) {}

```

```swift
var body: some View {
    VStack {
        if showButton {
            Button("Click me!", action: clicked)
        } else {
            Text("No button")
        }
        .someProperty // ❌ parsing ambiguity: static property, or property of View?
    }
}

var body: some View {
    VStack {
        (
            if showButton {
                Button("Click me!", action: clicked)
            } else {
                Text("No button")
            }
        ).someProperty // ✅ no parsing ambiguity
    }
}

```

…and I don’t think anybody identified a downside.

I don’t want the idea to get lost. It may well be too much to consider in _this_ proposal, but at a minimum, it’s a useful answer to those future direction concerns.

---

_[View the full topic](https://forums.swift.org/t/pitch-if-and-switch-expressions/61149)._
