# \#syntax

**URL:** https://forums.swift.org/tag/syntax/43.md

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

---

## [Negated type patterns in \`catch\`](https://forums.swift.org/t/negated-type-patterns-in-catch/90317)

<div class="topic-metadata">

**Author:** [@theoriginalbit](https://forums.swift.org/u/theoriginalbit)\
**Replies:** 5\
**Last updated:** [October 31, 2026, 12:34pm UTC](https://forums.swift.org/t/negated-type-patterns-in-catch/90317 "2026-10-31T12:34:35Z")

</div>

Has anyone else wanted a negated type pattern in catch? I couldn't find an earlier thread on this. Particularly since the introduction of typed-throws (SE-0413) I find myself often writing a forwarding clause when a do …

---

## [Labeled trailing closures](https://forums.swift.org/t/labeled-trailing-closures/90202)

<div class="topic-metadata">

**Author:** [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Replies:** 13\
**Last updated:** [October 23, 2026, 9:01am UTC](https://forums.swift.org/t/labeled-trailing-closures/90202 "2026-10-23T09:01:29Z")

</div>

Is there any appetite for allowing argument labels to be applied to the first trailing closure of a call expression? As things are now, we have to choose between indenting all closure arguments: presentDeletionModal( …

---

## [\[Pitch\] Surfaces](https://forums.swift.org/t/pitch-surfaces/88169)

<div class="topic-metadata">

**Author:** [@hollyschilling](https://forums.swift.org/u/hollyschilling)\
**Replies:** 14\
**Last updated:** [July 27, 2026, 3:56pm UTC](https://forums.swift.org/t/pitch-surfaces/88169 "2026-07-27T15:56:38Z")

</div>

Surfaces Proposal: SE-NNNN Author: Holly Schilling Review Manager: TBD Status: Draft Implementation: Pitch Companion work: PHP RFC: Surfaces (draft, same author) Introduction Swift's access levels describe where a decl…

---

## [Pitch: Conditional Property Setters with set(when:)](https://forums.swift.org/t/pitch-conditional-property-setters-with-set-when/82342)

<div class="topic-metadata">

**Author:** [@sdmarcotte](https://forums.swift.org/u/sdmarcotte)\
**Replies:** 0\
**Last updated:** [September 24, 2025, 7:02pm UTC](https://forums.swift.org/t/pitch-conditional-property-setters-with-set-when/82342 "2025-09-24T19:02:47Z")

</div>

Pitch: Conditional Property Setters with set(when:) Problem Swift's property observers (willSet/didSet) are called on every assignment, even when the assigned value is identical to the current value. This creates unneces…

---

## [Parsing question about the #whatever expressions](https://forums.swift.org/t/parsing-question-about-the-whatever-expressions/72313)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 3\
**Last updated:** [June 9, 2024, 11:09am UTC](https://forums.swift.org/t/parsing-question-about-the-whatever-expressions/72313 "2024-06-09T11:09:11Z")

</div>

Just took a very brief look through Swift Syntax. I recall there have been special expressions like "#file" that let you get out-of-band information. Looking through the various "...Syntax" protocols, I saw one about mac…

---

## [Filtered optional-try expressions](https://forums.swift.org/t/filtered-optional-try-expressions/72648)

<div class="topic-metadata">

**Author:** [@anselmschueler](https://forums.swift.org/u/anselmschueler)\
**Replies:** 1\
**Last updated:** [November 20, 2024, 9:21pm UTC](https://forums.swift.org/t/filtered-optional-try-expressions/72648 "2024-11-20T21:21:49Z")

</div>

Motivation With the try? operator, it’s easy to convert errors to optional values, which is useful for working with external code or when it’s unimportant what the error is. However, sometimes we want to handle some erro…

---

## [Lack of turbofish-like syntax for generics in expressions](https://forums.swift.org/t/lack-of-turbofish-like-syntax-for-generics-in-expressions/73889)

<div class="topic-metadata">

**Author:** [@bbb651](https://forums.swift.org/u/bbb651)\
**Replies:** 5\
**Last updated:** [August 11, 2024, 10:22pm UTC](https://forums.swift.org/t/lack-of-turbofish-like-syntax-for-generics-in-expressions/73889 "2024-08-11T22:22:01Z")

</div>

Hey, I'm very new to Swift, learning it for use in Ladybird and so far I like it :) One thing I've noticed is that generics in expressions uses the Type\<T\> syntax and not something like turbofish Type::\<T\> (or Type.\<T\> …

---

## [\[Discussion\] \`#if hasSymbol(Module.Symbol)\`, a compile time check for a module symbol's availability](https://forums.swift.org/t/discussion-if-hassymbol-module-symbol-a-compile-time-check-for-a-module-symbols-availability/58252)

<div class="topic-metadata">

**Author:** [@0x41c](https://forums.swift.org/u/0x41c)\
**Replies:** 33\
**Last updated:** [July 31, 2024, 12:58pm UTC](https://forums.swift.org/t/discussion-if-hassymbol-module-symbol-a-compile-time-check-for-a-module-symbols-availability/58252 "2024-07-31T12:58:56Z")

</div>

Description The hasSymbol compiler directive aims to be a viable alternative to availability where it has not been explicitly attributed, or where a symbol is available in a library on one platform, but not available on …

---

## [\[Proposal\] Set literals](https://forums.swift.org/t/proposal-set-literals/72929)

<div class="topic-metadata">

**Author:** [@crontab](https://forums.swift.org/u/crontab)\
**Replies:** 77\
**Last updated:** [July 12, 2024, 2:01pm UTC](https://forums.swift.org/t/proposal-set-literals/72929 "2024-07-12T14:01:56Z")

</div>

I am surprised this has only been discussed once and it was in 2016: \[Proposal\] Set literal and Set type syntax unless there were others that I can't find. Starting a new thread since the previous one is too old and too …

---

## [Can I choose what block a \`defer\` statements belongs to?](https://forums.swift.org/t/can-i-choose-what-block-a-defer-statements-belongs-to/72586)

<div class="topic-metadata">

**Author:** [@anselmschueler](https://forums.swift.org/u/anselmschueler)\
**Replies:** 10\
**Last updated:** [June 22, 2024, 9:54am UTC](https://forums.swift.org/t/can-i-choose-what-block-a-defer-statements-belongs-to/72586 "2024-06-22T09:54:46Z")

</div>

Suppose I have a function like this: func disposeController(\_ controller: Controller) { let requiresDisconnection; if controller.isConnected { requiresDisconnection = true gameManager.prepareHand…

---

## [More commas, fewer commas... no commas?](https://forums.swift.org/t/more-commas-fewer-commas-no-commas/70340)

<div class="topic-metadata">

**Author:** [@Hacksaw](https://forums.swift.org/u/Hacksaw)\
**Replies:** 15\
**Last updated:** [February 29, 2024, 5:07am UTC](https://forums.swift.org/t/more-commas-fewer-commas-no-commas/70340 "2024-02-29T05:07:47Z")

</div>

There's a few pitches discussing allowing trailing commas, and it made me wonder how people felt about no commas: var foo = \[ "bar" "fum" "quux" \] This would strictly be allowed when entries are separated by newlin…

---

## [Swift Next: Swift syntax package in async/await era — for Sublime Text 4](https://forums.swift.org/t/swift-next-swift-syntax-package-in-async-await-era-for-sublime-text-4/58227)

<div class="topic-metadata">

**Author:** [@aerobounce](https://forums.swift.org/u/aerobounce)\
**Replies:** 2\
**Last updated:** [February 5, 2024, 11:56am UTC](https://forums.swift.org/t/swift-next-swift-syntax-package-in-async-await-era-for-sublime-text-4/58227 "2024-02-05T11:56:42Z")

</div>

Hi community. I have been working on the Swift syntax file for Sublime Text 4 for a while, and published it today. Swift Next Features Full support of Swift 5.6 (some accepted / implemented proposals are supported i…

---

## [Pre-Pitch: \`@package\` argument syntax](https://forums.swift.org/t/pre-pitch-package-argument-syntax/63031)

<div class="topic-metadata">

**Author:** [@stevapple](https://forums.swift.org/u/stevapple)\
**Replies:** 8\
**Last updated:** [February 9, 2023, 8:38pm UTC](https://forums.swift.org/t/pre-pitch-package-argument-syntax/63031 "2023-02-09T20:38:16Z")

</div>

Hello folks at the Swift community! A year and a while ago, I started the work of supporting @package(...) import syntax for importing SwiftPM dependencies in Swift scripts as a GSoC project. During the project, I manag…

---

## [More Expressive Protocol Constraint Syntax](https://forums.swift.org/t/more-expressive-protocol-constraint-syntax/59801)

<div class="topic-metadata">

**Author:** [@ranveerm](https://forums.swift.org/u/ranveerm)\
**Replies:** 5\
**Last updated:** [August 22, 2022, 9:57am UTC](https://forums.swift.org/t/more-expressive-protocol-constraint-syntax/59801 "2022-08-22T09:57:04Z")

</div>

Swift 5 allows protocols to "constrain their conforming types to those that subclass a given class". This is implemented as (taken directly from the release notes)- protocol MyView: UIView { /\*...\*/ } protocol MyView w…

---

## [Aliases for the most used shorthand argument names](https://forums.swift.org/t/aliases-for-the-most-used-shorthand-argument-names/52360)

<div class="topic-metadata">

**Author:** [@sspringer](https://forums.swift.org/u/sspringer)\
**Replies:** 10\
**Last updated:** [September 27, 2021, 12:05pm UTC](https://forums.swift.org/t/aliases-for-the-most-used-shorthand-argument-names/52360 "2021-09-27T12:05:02Z")

</div>

$0 ... are here and will stay with us and think this naming scheme is perfectly fine. But (even with many arguments against it, see below): I think code would look much "nicer" when there would be – in addition to that …

---

## [Sub-syntax for string literals](https://forums.swift.org/t/sub-syntax-for-string-literals/50678)

<div class="topic-metadata">

**Author:** [@1oo7](https://forums.swift.org/u/1oo7)\
**Replies:** 9\
**Last updated:** [July 28, 2021, 11:57am UTC](https://forums.swift.org/t/sub-syntax-for-string-literals/50678 "2021-07-28T11:57:18Z")

</div>

Motivation Multi-line string literals often get used to embed JSON, Yaml, JavaScript, etc. into Swift code, especially in tests. However, for any given string literal, Swift does not seems to provide any official way to…

---

## [How would we change error detection and reporting to handle macros? (#dup, the Duplication Macro, part 4)](https://forums.swift.org/t/how-would-we-change-error-detection-and-reporting-to-handle-macros-dup-the-duplication-macro-part-4/40072)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 1\
**Last updated:** [September 6, 2020, 11:43pm UTC](https://forums.swift.org/t/how-would-we-change-error-detection-and-reporting-to-handle-macros-dup-the-duplication-macro-part-4/40072 "2020-09-06T23:43:49Z")

</div>

I've posted about a duplication macro before. Here's a revised grammar: Under identifiers (first two augment an existing production): identifier → duplication-marker implicit-parameter-name → $ ( duplication-marker…

---

## [Record initialization and destructuring syntax](https://forums.swift.org/t/record-initialization-and-destructuring-syntax/16631)

<div class="topic-metadata">

**Author:** [@Max\_Desiatov](https://forums.swift.org/u/Max_Desiatov)\
**Replies:** 60\
**Last updated:** [July 29, 2020, 11:43pm UTC](https://forums.swift.org/t/record-initialization-and-destructuring-syntax/16631 "2020-07-29T23:43:37Z")

</div>

Quite frequently there is a need to manually initialize structs/classes with a number of parameters that makes standard initializer syntax not ideal. Without Xcode autocomplete it's very hard to get order of parameter na…

---

## [Operators conform to protocols?](https://forums.swift.org/t/operators-conform-to-protocols/36767)

<div class="topic-metadata">

**Author:** [@wowbagger](https://forums.swift.org/u/wowbagger)\
**Replies:** 2\
**Last updated:** [May 22, 2020, 5:08pm UTC](https://forums.swift.org/t/operators-conform-to-protocols/36767 "2020-05-22T17:08:34Z")

</div>

I see that operator declarations use this syntax in the standard library: fixity operator: PrecedenceGroup, Protocol. This is undocumented. Is this some kind of protocol conformance or inheritance?

---

## [Concise Magic File Names](https://forums.swift.org/t/concise-magic-file-names/31297)

<div class="topic-metadata">

**Author:** [@beccadax](https://forums.swift.org/u/beccadax)\
**Replies:** 53\
**Last updated:** [May 15, 2020, 9:39pm UTC](https://forums.swift.org/t/concise-magic-file-names/31297 "2020-05-15T21:39:43Z")

</div>

In previous threads like We Need #fileName, we've generally agreed that the current #file feature makes some of the wrong tradeoffs by generating such a verbose path. I've prepared a proposal (and a matching implementati…

---

## [New SwiftUI like declarative syntax for Swift for servers](https://forums.swift.org/t/new-swiftui-like-declarative-syntax-for-swift-for-servers/32044)

<div class="topic-metadata">

**Author:** [@mehmet](https://forums.swift.org/u/mehmet)\
**Replies:** 6\
**Last updated:** [February 25, 2020, 3:41am UTC](https://forums.swift.org/t/new-swiftui-like-declarative-syntax-for-swift-for-servers/32044 "2020-02-25T03:41:14Z")

</div>

I've been using SwiftUI for a while and loving it. I've been wanting to program in swift on server side for so long. But all other server side swift solutions are same and makes no new ground. For example most server si…

---

## [How do I make a while loop that runs in the background?](https://forums.swift.org/t/how-do-i-make-a-while-loop-that-runs-in-the-background/20832)

<div class="topic-metadata">

**Author:** [@AppleNewbie123](https://forums.swift.org/u/AppleNewbie123)\
**Replies:** 7\
**Last updated:** [February 27, 2019, 4:53pm UTC](https://forums.swift.org/t/how-do-i-make-a-while-loop-that-runs-in-the-background/20832 "2019-02-27T16:53:02Z")

</div>

So when my game start function I want my enemies appear until the player dies: while isdead == false { self.delayWithSeconds(Double.random(in: 0.5...5)) { self.RightSpike.run(self.DownAndUpRight) } self.delayWithSec…

---

## [The scope of an unwrapped optional in an optional chain](https://forums.swift.org/t/the-scope-of-an-unwrapped-optional-in-an-optional-chain/17410)

<div class="topic-metadata">

**Author:** [@nekno](https://forums.swift.org/u/nekno)\
**Replies:** 4\
**Last updated:** [November 4, 2018, 9:27pm UTC](https://forums.swift.org/t/the-scope-of-an-unwrapped-optional-in-an-optional-chain/17410 "2018-11-04T21:27:07Z")

</div>

What is the scope/lifetime of an optional that successfully unwraps in an optional chain? For example: let closure = { \[weak self\] in self?.someMethod(with: self!.someProperty) } My understanding is that this execut…

---

## [Enum var field](https://forums.swift.org/t/enum-var-field/16749)

<div class="topic-metadata">

**Author:** [@Serendipity](https://forums.swift.org/u/Serendipity)\
**Replies:** 13\
**Last updated:** [October 8, 2018, 12:49pm UTC](https://forums.swift.org/t/enum-var-field/16749 "2018-10-08T12:49:24Z")

</div>

Hello folks. I got an idea of "enum var field" feature. Which is something like this. enum Foo { var bar: Int case qux(String) case kaz(fred: UInt8) var waldo: Double } Which is just a shorten form of; …

---

## [Building SwiftSyntax tool inside the toolchain](https://forums.swift.org/t/building-swiftsyntax-tool-inside-the-toolchain/14272)

<div class="topic-metadata">

**Author:** [@swift-analyzer](https://forums.swift.org/u/swift-analyzer)\
**Replies:** 1\
**Last updated:** [August 17, 2018, 11:16pm UTC](https://forums.swift.org/t/building-swiftsyntax-tool-inside-the-toolchain/14272 "2018-08-17T23:16:00Z")

</div>

I have been able to build a functional swift refactoring tool using the instructions given in https://github.com/apple/swift/tree/master/lib/Syntax. This has been built using Xcode (as given by the instructions in the li…

---

## [Temporary-Only Wrapper Types](https://forums.swift.org/t/temporary-only-wrapper-types/14843)

<div class="topic-metadata">

**Author:** [@technogen](https://forums.swift.org/u/technogen)\
**Replies:** 7\
**Last updated:** [July 31, 2018, 5:06am UTC](https://forums.swift.org/t/temporary-only-wrapper-types/14843 "2018-07-31T05:06:59Z")

</div>

There is a number of use cases where a type is necessary to encapsulate access to a specific part of a type without creating complex object graphs. The most representative example is the String type with its var unicodeS…

---

## [Syntactic Sugar for nested types in extensions](https://forums.swift.org/t/syntactic-sugar-for-nested-types-in-extensions/11299)

<div class="topic-metadata">

**Author:** [@rjstelling](https://forums.swift.org/u/rjstelling)\
**Replies:** 13\
**Last updated:** [March 30, 2018, 10:37am UTC](https://forums.swift.org/t/syntactic-sugar-for-nested-types-in-extensions/11299 "2018-03-30T10:37:00Z")

</div>

Preamble: I had this idea while writing a lot of nested types, at first it seems like a great idea that reduced "Pyramid of doom" type issues. I've since cooled on the idea, but I'm still on the fence and wanted to get…
