Syntax

Swift Guard Statement Syntax

In Swift, guard statement: exits early if a condition fails — guard let id else { return }

Quick Answer

Syntax
guard let id else { return }
SwiftSyntax

Guard Statement

Code example
guard let id else { return }

Exits early if a condition fails.

Learn More

How to guard statement in Swift

  1. Open your Swift file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Swift Guard Statement Syntax

Use guard let id else { return }.

Related Syntax References

Frequently asked questions

What is the Swift syntax for guard statement?

Use this pattern: guard let id else { return }

Can I copy this Swift code example?

Yes. Use Copy code and adapt the example to your program.

Is this Swift syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify