# \#pattern-matching

**URL:** https://forums.swift.org/tag/pattern-matching/281.md

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

---

## [IntentFlow: an experimental workflow-first architecture for iOS apps](https://forums.swift.org/t/intentflow-an-experimental-workflow-first-architecture-for-ios-apps/88100)

<div class="topic-metadata">

**Author:** [@emrecanozturk](https://forums.swift.org/u/emrecanozturk)\
**Replies:** 0\
**Last updated:** [July 7, 2026, 6:46am UTC](https://forums.swift.org/t/intentflow-an-experimental-workflow-first-architecture-for-ios-apps/88100 "2026-07-07T06:46:06Z")

</div>

Hi everyone, I wanted to share an experimental iOS architecture proposal I have been working on: IntentFlow IntentFlow is a workflow-first, AI-ready architecture for iOS apps. The core idea is to model feature behavi…

---

## [InlineArray pattern matching and destructuring](https://forums.swift.org/t/inlinearray-pattern-matching-and-destructuring/84032)

<div class="topic-metadata">

**Author:** [@Lancelotbronner](https://forums.swift.org/u/Lancelotbronner)\
**Replies:** 9\
**Last updated:** [June 21, 2026, 10:14am UTC](https://forums.swift.org/t/inlinearray-pattern-matching-and-destructuring/84032 "2026-06-21T10:14:00Z")

</div>

I have come across a need in pattern matching an InlineArray and was very surprised to find out that while I can do this: @available(macOS 26, \*) mutating func names\<let count: Int\>() -\> \[count of Name\] { InlineArray {…

---

## [Pattern-Matching Shortcuts in Swift-Testing?](https://forums.swift.org/t/pattern-matching-shortcuts-in-swift-testing/73305)

<div class="topic-metadata">

**Author:** [@vanvoorden](https://forums.swift.org/u/vanvoorden)\
**Replies:** 3\
**Last updated:** [July 20, 2024, 10:25am UTC](https://forums.swift.org/t/pattern-matching-shortcuts-in-swift-testing/73305 "2024-07-20T10:25:48Z")

</div>

Hi! I have some tests that are using pattern matching to derive some state (and then testing the value of that state). Here is an example: enum E { case a(x: Int, y: Int) case b } @Test func t1() throws { let e =…

---

## [Concise pattern matching for enum cases with associated values?](https://forums.swift.org/t/concise-pattern-matching-for-enum-cases-with-associated-values/75529)

<div class="topic-metadata">

**Author:** [@Jens](https://forums.swift.org/u/Jens)\
**Replies:** 3\
**Last updated:** [October 22, 2024, 1:31pm UTC](https://forums.swift.org/t/concise-pattern-matching-for-enum-cases-with-associated-values/75529 "2024-10-22T13:31:48Z")

</div>

Apologies if this has been asked before, but I couldn't find any related threads. ~= works for simple cases like .foo , but for cases with associated values like .bar , it requires more verbose handling: enum E: Equata…

---

## [Pattern of type 'E\<E\<T\>\>' cannot match 'E\<T\>'](https://forums.swift.org/t/pattern-of-type-e-e-t-cannot-match-e-t/75129)

<div class="topic-metadata">

**Author:** [@idrougge](https://forums.swift.org/u/idrougge)\
**Replies:** 4\
**Last updated:** [October 3, 2024, 12:32pm UTC](https://forums.swift.org/t/pattern-of-type-e-e-t-cannot-match-e-t/75129 "2024-10-03T12:32:51Z")

</div>

Given an enum E with an associated generic value T where I implement a ~= overload to match an enum case with a value T, I run into a puzzling compiler error: enum E\<T\> { case t(T) } func ~=\<T\> (lhs: T, rhs: E\<T\>) …

---

## [Why is my custom \`~=\` operator not detected?](https://forums.swift.org/t/why-is-my-custom-operator-not-detected/74431)

<div class="topic-metadata">

**Author:** [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Replies:** 5\
**Last updated:** [September 8, 2024, 8:14pm UTC](https://forums.swift.org/t/why-is-my-custom-operator-not-detected/74431 "2024-09-08T20:14:19Z")

</div>

I'm trying to demonstrate to someone that you can use a custom operator ~= for pattern-matching. Yet, for some reason, when I try to run the code below, I always get an error "pattern of type 'Parity' cannot match 'Int'"…

---

## [Property Wrappers in Pattern Matching](https://forums.swift.org/t/property-wrappers-in-pattern-matching/67912)

<div class="topic-metadata">

**Author:** [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Replies:** 2\
**Last updated:** [October 17, 2023, 9:45pm UTC](https://forums.swift.org/t/property-wrappers-in-pattern-matching/67912 "2023-10-17T21:45:04Z")

</div>

While working with low-level code for a sort of linked list, I found myself accessing .pointee a lot. Enough that I wanted an abbreviation for it. Since prefix func \* wouldn't work the way it does in C (it would be read-…

---

## [Pattern matching and binding simultaneously?](https://forums.swift.org/t/pattern-matching-and-binding-simultaneously/60574)

<div class="topic-metadata">

**Author:** [@idrougge](https://forums.swift.org/u/idrougge)\
**Replies:** 11\
**Last updated:** [September 30, 2022, 10:08pm UTC](https://forums.swift.org/t/pattern-matching-and-binding-simultaneously/60574 "2022-09-30T22:08:09Z")

</div>

Pattern matching lets you either match a pattern or bind a value, but not at the same time, as far as I can tell. An example: enum Response { case success(MyStruct) case failure(Error) } enum MyError: Error { …

---

## [Pattern matching similar enum cases seems broken](https://forums.swift.org/t/pattern-matching-similar-enum-cases-seems-broken/60499)

<div class="topic-metadata">

**Author:** [@dented42](https://forums.swift.org/u/dented42)\
**Replies:** 4\
**Last updated:** [September 26, 2022, 3:54am UTC](https://forums.swift.org/t/pattern-matching-similar-enum-cases-seems-broken/60499 "2022-09-26T03:54:46Z")

</div>

This feels like a language bug but it's possible I'm just holding it wrong. I'm able to construct an enum like the following: enum Thing { case thing(Int) case thing(Int, Int) case thing(Int, also: String) } The …

---

## [Please help me understand pattern matching](https://forums.swift.org/t/please-help-me-understand-pattern-matching/54536)

<div class="topic-metadata">

**Author:** [@xjru](https://forums.swift.org/u/xjru)\
**Replies:** 13\
**Last updated:** [January 11, 2022, 9:38am UTC](https://forums.swift.org/t/please-help-me-understand-pattern-matching/54536 "2022-01-11T09:38:49Z")

</div>

Hi, I don't fully understand how pattern matching works. Please help me understand what happens in this example: struct Iter: IteratorProtocol { var step: (Int)-\>Int? var current: Int init(\_ initial: In…

---

## [Stating aliased type explicitly during pattern variable binding gives me an error](https://forums.swift.org/t/stating-aliased-type-explicitly-during-pattern-variable-binding-gives-me-an-error/52735)

<div class="topic-metadata">

**Author:** [@ChrisOffner](https://forums.swift.org/u/ChrisOffner)\
**Replies:** 1\
**Last updated:** [October 11, 2021, 5:49pm UTC](https://forums.swift.org/t/stating-aliased-type-explicitly-during-pattern-variable-binding-gives-me-an-error/52735 "2021-10-11T17:49:31Z")

</div>

This code gives me the commented error: struct T { } public typealias Alias\<S\> = Result\<S, NSError\> let response: Alias\<T\> = .success(T()) if case let Alias.success(value) = response { // ❌ Operator function '~=' req…

---

## [Access control for enum cases](https://forums.swift.org/t/access-control-for-enum-cases/47142)

<div class="topic-metadata">

**Author:** [@typesanitizer](https://forums.swift.org/u/typesanitizer)\
**Replies:** 54\
**Last updated:** [May 10, 2021, 12:41pm UTC](https://forums.swift.org/t/access-control-for-enum-cases/47142 "2021-05-10T12:41:30Z")

</div>

Introduction Today, Swift doesn't allow access control modifiers on enum cases, unlike properties, methods and other kinds of declarations. This proposal fixes that hole in the language, making it more uniform. Motivati…

---

## [Value binding in custom pattern matching](https://forums.swift.org/t/value-binding-in-custom-pattern-matching/47445)

<div class="topic-metadata">

**Author:** [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Replies:** 1\
**Last updated:** [April 15, 2021, 1:08am UTC](https://forums.swift.org/t/value-binding-in-custom-pattern-matching/47445 "2021-04-15T01:08:55Z")

</div>

I quite like the ability to overload the pattern matching operator ~=. It allows for some very expressive stuff. I'm wondering if there is any way to bind a custom value for use in the matched switch branch. For example,…

---

## [Allowing @unknown in arbitrarily nested patterns](https://forums.swift.org/t/allowing-unknown-in-arbitrarily-nested-patterns/47224)

<div class="topic-metadata">

**Author:** [@typesanitizer](https://forums.swift.org/u/typesanitizer)\
**Replies:** 11\
**Last updated:** [April 13, 2021, 5:04am UTC](https://forums.swift.org/t/allowing-unknown-in-arbitrarily-nested-patterns/47224 "2021-04-13T05:04:41Z")

</div>

Every pattern I ever wrote is here within this walls I'm sorry, language nerds, but I'm blocking out your calls I've had my evolution pitch, I don't need something new I'm afraid of what I'll implement if I follow yo…

---

## [If case let, guard case let, for case let](https://forums.swift.org/t/if-case-let-guard-case-let-for-case-let/37910)

<div class="topic-metadata">

**Author:** [@wowbagger](https://forums.swift.org/u/wowbagger)\
**Replies:** 3\
**Last updated:** [June 25, 2020, 7:48pm UTC](https://forums.swift.org/t/if-case-let-guard-case-let-for-case-let/37910 "2020-06-25T19:48:42Z")

</div>

At the 16:43 mark of WWDC20 session 10189 is this code snippet: func handleIncomingFile(\_ incomingResourceURL: URL, with name: String, from fromID: String) { guard case let safeFileName = name.lastPathCompo…

---

## [Aggregating errors and pattern matching](https://forums.swift.org/t/aggregating-errors-and-pattern-matching/34995)

<div class="topic-metadata">

**Author:** [@sveinhal](https://forums.swift.org/u/sveinhal)\
**Replies:** 4\
**Last updated:** [April 2, 2020, 3:20pm UTC](https://forums.swift.org/t/aggregating-errors-and-pattern-matching/34995 "2020-04-02T15:20:28Z")

</div>

I'm using a home made promise implementation with strongly typed errors throughout my code base, but my question is equally valid for Combine's publishers and just old plain Swift.Result.Failure: It is often the case th…

---

## [Commutative Pattern Matching](https://forums.swift.org/t/commutative-pattern-matching/29275)

<div class="topic-metadata">

**Author:** [@Wildchild9](https://forums.swift.org/u/Wildchild9)\
**Replies:** 4\
**Last updated:** [September 30, 2019, 5:40am UTC](https://forums.swift.org/t/commutative-pattern-matching/29275 "2019-09-30T05:40:01Z")

</div>

I am currently working on building a simplifier for mathematical expressions. I want to find a way to match certain cases commutatively while still being able to bind values in patterns. So... for a bit more insight int…
