# \#guard

**URL:** https://forums.swift.org/tag/guard/475.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [\[Pitch\] \`guard do ... catch\`: local error handling with early-exit and bound variables](https://forums.swift.org/t/pitch-guard-do-catch-local-error-handling-with-early-exit-and-bound-variables/90330)

<div class="topic-metadata">

**Author:** [@laptudirm](https://forums.swift.org/u/laptudirm)\
**Replies:** 15\
**Last updated:** [November 1, 2026, 9:21am UTC](https://forums.swift.org/t/pitch-guard-do-catch-local-error-handling-with-early-exit-and-bound-variables/90330 "2026-11-01T09:21:27Z")

</div>

Motivation It is a common pattern to have a throwing function whose result needs to be bound for use in the enclosing scope. let value = try thrower() // We want to handle any thrown errors and exit early // so that the…

---

## ["fallthrough" + "guard/else"](https://forums.swift.org/t/fallthrough-guard-else/72680)

<div class="topic-metadata">

**Author:** [@RoBo-Inc](https://forums.swift.org/u/RoBo-Inc)\
**Replies:** 3\
**Last updated:** [August 13, 2025, 4:49pm UTC](https://forums.swift.org/t/fallthrough-guard-else/72680 "2025-08-13T16:49:42Z")

</div>

Can anybody please confirm, that this usage of "fallthrough" is eligible? :pray: (the code compiles) extension URLRequest { init(url: URL, httpMethod: HTTPMethod, token: String? = nil) { switch httpMethod { …

---

## [\`if {} else {} else {}\` actually works when combining if expressions with guard](https://forums.swift.org/t/if-else-else-actually-works-when-combining-if-expressions-with-guard/70766)

<div class="topic-metadata">

**Author:** [@wadetregaskis](https://forums.swift.org/u/wadetregaskis)\
**Replies:** 6\
**Last updated:** [March 19, 2024, 3:28am UTC](https://forums.swift.org/t/if-else-else-actually-works-when-combining-if-expressions-with-guard/70766 "2024-03-19T03:28:53Z")

</div>

let getter: () -\> String? = { MainActor.assumeIsolated { … } } guard let text = if Thread.isMainThread { getter() } else { DispatchQueue.main.sync(execute: getter) } else { return false } Ig…

---

## [Assert-let for special cases at runtime](https://forums.swift.org/t/assert-let-for-special-cases-at-runtime/70293)

<div class="topic-metadata">

**Author:** [@picnicbob](https://forums.swift.org/u/picnicbob)\
**Replies:** 10\
**Last updated:** [February 27, 2024, 3:12pm UTC](https://forums.swift.org/t/assert-let-for-special-cases-at-runtime/70293 "2024-02-27T15:12:04Z")

</div>

There are times, especially when handling special cases inside a function, that I would like to perform an action if a let statement evaluates to false and then continue with the normal code flow. Essentially it's a guar…

---

## [Support for returning the result of a Guard statement](https://forums.swift.org/t/support-for-returning-the-result-of-a-guard-statement/67497)

<div class="topic-metadata">

**Author:** [@totidev](https://forums.swift.org/u/totidev)\
**Replies:** 21\
**Last updated:** [October 3, 2023, 1:10pm UTC](https://forums.swift.org/t/support-for-returning-the-result-of-a-guard-statement/67497 "2023-10-03T13:10:20Z")

</div>

I have a suggestion to allow a guard return statement. There are times when you unwrap an optional, and if there is no value, you may throw an error, and then return the value. For example: let value: Int? = 0 guard let…

---

## [Guard unowned / while unowned](https://forums.swift.org/t/guard-unowned-while-unowned/65401)

<div class="topic-metadata">

**Author:** [@picnicbob](https://forums.swift.org/u/picnicbob)\
**Replies:** 6\
**Last updated:** [June 7, 2023, 4:24pm UTC](https://forums.swift.org/t/guard-unowned-while-unowned/65401 "2023-06-07T16:24:30Z")

</div>

At the moment it doesn't seem possible to define an unowned local variable in a guard statement or while loop. For example, I would like to be able to: guard unowned let firstNode else { return } or while unowned …

---

## [Variable redefinition via guard](https://forums.swift.org/t/variable-redefinition-via-guard/54414)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 16\
**Last updated:** [January 5, 2022, 5:50am UTC](https://forums.swift.org/t/variable-redefinition-via-guard/54414 "2022-01-05T05:50:36Z")

</div>

Is it a bug or a feature that I can redefine a variable in the same scope via guard? Or is the scope different here? (the scope is the same here, you can check this by defining another unrelated variable with "let x = 0"…

---

## [Adding Sugar for Preconditions and Guards](https://forums.swift.org/t/adding-sugar-for-preconditions-and-guards/43520)

<div class="topic-metadata">

**Author:** [@SlaunchaMan](https://forums.swift.org/u/SlaunchaMan)\
**Replies:** 14\
**Last updated:** [March 19, 2021, 2:16pm UTC](https://forums.swift.org/t/adding-sugar-for-preconditions-and-guards/43520 "2021-03-19T14:16:20Z")

</div>

Over the years there have been some requests to shorten something like this: guard let foo = foo else { return } to something like this: guard let foo While I think that syntax is probably a little too sugary, la…

---

## ["'break' is only allowed inside a loop, if, do, or switch" error message inside guard statement is misleading](https://forums.swift.org/t/break-is-only-allowed-inside-a-loop-if-do-or-switch-error-message-inside-guard-statement-is-misleading/45180)

<div class="topic-metadata">

**Author:** [@orchetect](https://forums.swift.org/u/orchetect)\
**Replies:** 9\
**Last updated:** [March 1, 2021, 9:53pm UTC](https://forums.swift.org/t/break-is-only-allowed-inside-a-loop-if-do-or-switch-error-message-inside-guard-statement-is-misleading/45180 "2021-03-01T21:53:28Z")

</div>

When break is used in a guard statement within a do { } block, the error message states that break can be used in a do block which is quite confusing. Only when you change the guard statement to an if statement does a…
