# \#protocols

**URL:** https://forums.swift.org/tag/protocols/86.md

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

---

## [\[Pitch\] Make protocol conformance resolution demand-driven](https://forums.swift.org/t/pitch-make-protocol-conformance-resolution-demand-driven/87792)

<div class="topic-metadata">

**Author:** [@AdamCmiel](https://forums.swift.org/u/AdamCmiel)\
**Replies:** 5\
**Last updated:** [October 15, 2026, 3:43am UTC](https://forums.swift.org/t/pitch-make-protocol-conformance-resolution-demand-driven/87792 "2026-10-15T03:43:01Z")

</div>

I'd welcome feedback on the incremental approach outlined below, particularly whether the Inherited-stage unification is the right first step, and whether anyone sees cycle risks I've missed, or if this has been tried al…

---

## [Unorthodox recursive data structures](https://forums.swift.org/t/unorthodox-recursive-data-structures/89885)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 2\
**Last updated:** [October 4, 2026, 10:28am UTC](https://forums.swift.org/t/unorthodox-recursive-data-structures/89885 "2026-10-04T10:28:48Z")

</div>

The topic name is a bit misleading as what's discussed here: could be mutable could be truly allocation free, could be stack allocated or in some cases uses heap allocation behind the curtains. could be truly dynamic (…

---

## [Is it possible to make a Functor protocol?](https://forums.swift.org/t/is-it-possible-to-make-a-functor-protocol/89758)

<div class="topic-metadata">

**Author:** [@Oleksii\_Skidan](https://forums.swift.org/u/Oleksii_Skidan)\
**Replies:** 11\
**Last updated:** [September 26, 2026, 7:54pm UTC](https://forums.swift.org/t/is-it-possible-to-make-a-functor-protocol/89758 "2026-09-26T19:54:38Z")

</div>

:waving\_hand: Hi everyone, Prelude I know that adjacent topics have been discussed on this forum over the years. Back in the day (Swift 3 era) everybody was waiting for generics to evolve. Now it's Swift 6 era, and it …

---

## [Optimal way to scope mutability with Swift 6.4](https://forums.swift.org/t/optimal-way-to-scope-mutability-with-swift-6-4/89044)

<div class="topic-metadata">

**Author:** [@craigwrong](https://forums.swift.org/u/craigwrong)\
**Replies:** 4\
**Last updated:** [August 19, 2026, 1:22pm UTC](https://forums.swift.org/t/optimal-way-to-scope-mutability-with-swift-6-4/89044 "2026-08-19T13:22:56Z")

</div>

Hello! First of all apologies if this topic has been discussed before. Working on a highly concurrent code base I was tempted to make all my structs completely immutable. All members are other constant structs and are …

---

## [Recursive protocol conformance requirement](https://forums.swift.org/t/recursive-protocol-conformance-requirement/88978)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 8\
**Last updated:** [August 16, 2026, 10:05am UTC](https://forums.swift.org/t/recursive-protocol-conformance-requirement/88978 "2026-08-16T10:05:14Z")

</div>

I have a use case where having a feature similar to Equatable, Hashable, Codable (perhaps a few others?) would help: transitive protocol conformance requirement. protocol P /\* : TransitiveConformanceRequired \*/ {} ex…

---

## [Protocols in generics would be so useful](https://forums.swift.org/t/protocols-in-generics-would-be-so-useful/88768)

<div class="topic-metadata">

**Author:** [@No\_Pen\_3825](https://forums.swift.org/u/No_Pen_3825)\
**Replies:** 0\
**Last updated:** [August 4, 2026, 3:21pm UTC](https://forums.swift.org/t/protocols-in-generics-would-be-so-useful/88768 "2026-08-04T15:21:15Z")

</div>

I want to write something like below (a type safe components container where I can swap the kind of protocol), but it'd require a generic be a protocol rather than something concrete. I believe the closest I can nativel…

---

## [Methods with default implementation in internal protocol match public requirement of another protocol](https://forums.swift.org/t/methods-with-default-implementation-in-internal-protocol-match-public-requirement-of-another-protocol/88678)

<div class="topic-metadata">

**Author:** [@Serika\_PHB](https://forums.swift.org/u/Serika_PHB)\
**Replies:** 0\
**Last updated:** [July 31, 2026, 2:55pm UTC](https://forums.swift.org/t/methods-with-default-implementation-in-internal-protocol-match-public-requirement-of-another-protocol/88678 "2026-07-31T14:55:00Z")

</div>

In the following code, we have a public protocol and an internal one defining a method that matches the one in the public protocol. And we have a struct that conforms to both protocols public protocol MyProtocol { f…

---

## [@FunctionalProtocol – Zero-cost closure wrappers for SAM protocols](https://forums.swift.org/t/functionalprotocol-zero-cost-closure-wrappers-for-sam-protocols/88280)

<div class="topic-metadata">

**Author:** [@CodebyCR](https://forums.swift.org/u/CodebyCR)\
**Replies:** 2\
**Last updated:** [July 15, 2026, 6:57am UTC](https://forums.swift.org/t/functionalprotocol-zero-cost-closure-wrappers-for-sam-protocols/88280 "2026-07-15T06:57:03Z")

</div>

Hey Swift Community, Based on some other topics: FunctionalProtocols for Swift Anonymous Structs Merging Closure into Protocols I built a ⁠@FunctionalProtocol⁠ macro that generates zero-cost wrapper structur…

---

## [Is only one of these methods being used for compliance?](https://forums.swift.org/t/is-only-one-of-these-methods-being-used-for-compliance/88093)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 0\
**Last updated:** [July 6, 2026, 9:30pm UTC](https://forums.swift.org/t/is-only-one-of-these-methods-being-used-for-compliance/88093 "2026-07-06T21:30:40Z")

</div>

I have these in a Collection type I'm writing, when I activate the interface mode: public mutating func append(\_ newElement: some StringProtocol) /// Adds the elements of a sequence or collection to the end of …

---

## [Protocol private(set) properties](https://forums.swift.org/t/protocol-private-set-properties/70842)

<div class="topic-metadata">

**Author:** [@GiumaSoft](https://forums.swift.org/u/GiumaSoft)\
**Replies:** 7\
**Last updated:** [May 25, 2026, 4:19pm UTC](https://forums.swift.org/t/protocol-private-set-properties/70842 "2026-05-25T16:19:58Z")

</div>

I would like to prevent write access from outside my class to a property defined by protocol conformance. protocol MutableClientProtocol { associatedType Client var client: Client { get private(set) } mutat…

---

## [TypeEraserGenerator: Extensive set of macros for creating type erasers for protocols](https://forums.swift.org/t/typeerasergenerator-extensive-set-of-macros-for-creating-type-erasers-for-protocols/86619)

<div class="topic-metadata">

**Author:** [@atifdev10](https://forums.swift.org/u/atifdev10)\
**Replies:** 0\
**Last updated:** [May 9, 2026, 7:25pm UTC](https://forums.swift.org/t/typeerasergenerator-extensive-set-of-macros-for-creating-type-erasers-for-protocols/86619 "2026-05-09T19:25:56Z")

</div>

Hello swifters, I have been working on an package named TypeEraserGenerator (I know, very creative naming) which has an extensive set of macros for generating type erasers for protocols. It has support for associated t…

---

## [Protocol negative conformance](https://forums.swift.org/t/protocol-negative-conformance/86241)

<div class="topic-metadata">

**Author:** [@marlonjames71](https://forums.swift.org/u/marlonjames71)\
**Replies:** 7\
**Last updated:** [April 29, 2026, 4:47pm UTC](https://forums.swift.org/t/protocol-negative-conformance/86241 "2026-04-29T16:47:10Z")

</div>

This may not be sound, but I'm asking out of curiosity. Has there been any discussion about a Swift feature for negative protocol conformances — the ability to explicitly declare what types cannot conform to a given pro…

---

## [Protocol design with internal storage requirements — usable from external modules?](https://forums.swift.org/t/protocol-design-with-internal-storage-requirements-usable-from-external-modules/85801)

<div class="topic-metadata">

**Author:** [@miyoshitakaaki](https://forums.swift.org/u/miyoshitakaaki)\
**Replies:** 3\
**Last updated:** [April 9, 2026, 10:08am UTC](https://forums.swift.org/t/protocol-design-with-internal-storage-requirements-usable-from-external-modules/85801 "2026-04-09T10:08:01Z")

</div>

Hi, I have a question about protocol design and access control in Swift, especially regarding usage from external modules. I want to design a protocol where: a method is public some properties required for implem…

---

## [Conform to generic protocol twice](https://forums.swift.org/t/conform-to-generic-protocol-twice/85402)

<div class="topic-metadata">

**Author:** [@a7medev](https://forums.swift.org/u/a7medev)\
**Replies:** 9\
**Last updated:** [March 18, 2026, 8:32am UTC](https://forums.swift.org/t/conform-to-generic-protocol-twice/85402 "2026-03-18T08:32:03Z")

</div>

I have the following generic protocol: protocol EventListener\<Event\> { associatedtype Event func onEvent(\_ event: Event) } Some classes can receive different events, so they should conform to EventListener mul…

---

## [Pitch: Non-Public Protocol Requirements](https://forums.swift.org/t/pitch-non-public-protocol-requirements/84624)

<div class="topic-metadata">

**Author:** [@tiagocanto01](https://forums.swift.org/u/tiagocanto01)\
**Replies:** 18\
**Last updated:** [February 13, 2026, 2:24pm UTC](https://forums.swift.org/t/pitch-non-public-protocol-requirements/84624 "2026-02-13T14:24:14Z")

</div>

Swift protocols currently have no way to express requirements that must be implemented by conforming types but are not intended to be part of the public API of those types. As a result, protocol authors often have to ex…

---

## [I reimplemented Foundation's JSONEncoder and made it 33% faster using compile-time strategy dispatch](https://forums.swift.org/t/i-reimplemented-foundations-jsonencoder-and-made-it-33-faster-using-compile-time-strategy-dispatch/84195)

<div class="topic-metadata">

**Author:** [@couchdeveloper](https://forums.swift.org/u/couchdeveloper)\
**Replies:** 7\
**Last updated:** [January 19, 2026, 7:55am UTC](https://forums.swift.org/t/i-reimplemented-foundations-jsonencoder-and-made-it-33-faster-using-compile-time-strategy-dispatch/84195 "2026-01-19T07:55:19Z")

</div>

I recently explored whether Swift's type system and compiler could eliminate runtime overhead in encoding, and the results were surprising: a 33% performance improvement over Foundation's JSONEncoder using clean, maintai…

---

## [Referring to static variable of protocol via KeyPath leads to nonzero exit code](https://forums.swift.org/t/referring-to-static-variable-of-protocol-via-keypath-leads-to-nonzero-exit-code/83565)

<div class="topic-metadata">

**Author:** [@atifdev10](https://forums.swift.org/u/atifdev10)\
**Replies:** 4\
**Last updated:** [December 4, 2025, 7:08pm UTC](https://forums.swift.org/t/referring-to-static-variable-of-protocol-via-keypath-leads-to-nonzero-exit-code/83565 "2025-12-04T19:08:29Z")

</div>

While I was messing around with keypaths, I ran into this issue: protocol Foo { static var value: Int { get } } let keypath: KeyPath\<any Foo.Type, Int\> = \\.value // Doesn't compile If I try to create a keypath of …

---

## [How cursed is my Type Erasing pattern?](https://forums.swift.org/t/how-cursed-is-my-type-erasing-pattern/83355)

<div class="topic-metadata">

**Author:** [@ARG07](https://forums.swift.org/u/ARG07)\
**Replies:** 4\
**Last updated:** [November 30, 2025, 6:24pm UTC](https://forums.swift.org/t/how-cursed-is-my-type-erasing-pattern/83355 "2025-11-30T18:24:42Z")

</div>

Hi, I am developing an library to be used internally in our team. I currently have an Type Erasing system that works. But I am having doubts about its maintainability since it feels awkward to even look at and I couldn’…

---

## [Synchronous getter vs. @MainActor property — why is this allowed?](https://forums.swift.org/t/synchronous-getter-vs-mainactor-property-why-is-this-allowed/82991)

<div class="topic-metadata">

**Author:** [@David2XN](https://forums.swift.org/u/David2XN)\
**Replies:** 1\
**Last updated:** [November 3, 2025, 3:42pm UTC](https://forums.swift.org/t/synchronous-getter-vs-mainactor-property-why-is-this-allowed/82991 "2025-11-03T15:42:45Z")

</div>

How is it possible that I can conform to a protocol requiring a synchronous getter and also mark the concrete property as @MainActor at the same time? protocol MyProtocol { var syncStuff: String { get } } class My…

---

## [How Can A Document Data Model Use Compound Types? ( And What Is The SpreadSheet Type? )](https://forums.swift.org/t/how-can-a-document-data-model-use-compound-types-and-what-is-the-spreadsheet-type/80783)

<div class="topic-metadata">

**Author:** [@12GreenTrees](https://forums.swift.org/u/12GreenTrees)\
**Replies:** 9\
**Last updated:** [October 27, 2025, 4:06pm UTC](https://forums.swift.org/t/how-can-a-document-data-model-use-compound-types-and-what-is-the-spreadsheet-type/80783 "2025-10-27T16:06:12Z")

</div>

There seems to be a lack of information on how to put data models with compound types in document types, and then provide it to document Scenes. ( If “compound types” is the right term to cover both struct’s equivalent o…

---

## [Xcode Previews, Predicate, and KeyPath issues](https://forums.swift.org/t/xcode-previews-predicate-and-keypath-issues/80782)

<div class="topic-metadata">

**Author:** [@atlantis](https://forums.swift.org/u/atlantis)\
**Replies:** 3\
**Last updated:** [October 12, 2025, 3:08pm UTC](https://forums.swift.org/t/xcode-previews-predicate-and-keypath-issues/80782 "2025-10-12T15:08:26Z")

</div>

There were changes made to Xcode Previews last year that caused my applications to crash relating with SwiftData and KeyPaths when using protocols or generics. It turns out that it was passing an unknown KeyPath from the…

---

## [Switching on protocols](https://forums.swift.org/t/switching-on-protocols/82002)

<div class="topic-metadata">

**Author:** [@stever](https://forums.swift.org/u/stever)\
**Replies:** 6\
**Last updated:** [September 11, 2025, 3:03pm UTC](https://forums.swift.org/t/switching-on-protocols/82002 "2025-09-11T15:03:52Z")

</div>

Hey everyone, I ran into an unusual situation and I’m wondering why it is the way it is and what’s the best practice for this case. Say I have a factory function that spits out concrete types when requested a protocol: …

---

## [Improving JSONDecoder/Encoder Performance for large apps](https://forums.swift.org/t/improving-jsondecoder-encoder-performance-for-large-apps/81839)

<div class="topic-metadata">

**Author:** [@k.benua](https://forums.swift.org/u/k.benua)\
**Replies:** 11\
**Last updated:** [September 8, 2025, 9:28pm UTC](https://forums.swift.org/t/improving-jsondecoder-encoder-performance-for-large-apps/81839 "2025-09-08T21:28:38Z")

</div>

Table of Contents Purpose JSONDecoder/Encoder Performance Problem JSONDecoder Performance Flaws Proposed Optimizations Optimizations Results Apple Benchmark Overview Apple Benchmark Flaws My Benchm…

---

## [Is there a way to convert between an existential type and the existential metatype of the same protocol, statically?](https://forums.swift.org/t/is-there-a-way-to-convert-between-an-existential-type-and-the-existential-metatype-of-the-same-protocol-statically/81897)

<div class="topic-metadata">

**Author:** [@Danny](https://forums.swift.org/u/Danny)\
**Replies:** 2\
**Last updated:** [September 1, 2025, 3:58am UTC](https://forums.swift.org/t/is-there-a-way-to-convert-between-an-existential-type-and-the-existential-metatype-of-the-same-protocol-statically/81897 "2025-09-01T03:58:31Z")

</div>

For example, is there any way to combine both of these associated types into one, and base the other off of it? I don't think so. protocol P { } protocol EP { associatedtype AnyP associatedtype AnyPType } enum E: …

---

## [How do you incorporate a protocol's static members into another type's extensions by way of a generic placeholder?](https://forums.swift.org/t/how-do-you-incorporate-a-protocols-static-members-into-another-types-extensions-by-way-of-a-generic-placeholder/81848)

<div class="topic-metadata">

**Author:** [@Danny](https://forums.swift.org/u/Danny)\
**Replies:** 2\
**Last updated:** [August 29, 2025, 7:14am UTC](https://forums.swift.org/t/how-do-you-incorporate-a-protocols-static-members-into-another-types-extensions-by-way-of-a-generic-placeholder/81848 "2025-08-29T07:14:54Z")

</div>

If a protocol, represented in a generic placeholder (ModifiedCircle.Modifier, here) has static members, and you want to use them in an extension to another type, is there any better option than passing along the metatype…

---

## [How best to emulate protocols with private requirements?](https://forums.swift.org/t/how-best-to-emulate-protocols-with-private-requirements/81735)

<div class="topic-metadata">

**Author:** [@Danny](https://forums.swift.org/u/Danny)\
**Replies:** 5\
**Last updated:** [August 21, 2025, 11:53pm UTC](https://forums.swift.org/t/how-best-to-emulate-protocols-with-private-requirements/81735 "2025-08-21T23:53:14Z")

</div>

Swift doesn’t support protocols with greater visibility than their requirements. So what is the best technique available to emulate it? Here, there are two types, S1 and S2, which are generic over types that conform to…

---

## [My frustration with Generics and Protocols](https://forums.swift.org/t/my-frustration-with-generics-and-protocols/81668)

<div class="topic-metadata">

**Author:** [@brustolin](https://forums.swift.org/u/brustolin)\
**Replies:** 16\
**Last updated:** [August 17, 2025, 9:31am UTC](https://forums.swift.org/t/my-frustration-with-generics-and-protocols/81668 "2025-08-17T09:31:23Z")

</div>

I don’t know what Swift engineer had in mind when they decided to use this existential concept. Why this doesn’t work: protocol MyDelegate : AnyObject { } final class WeakDelegate\<T: AnyObject\> { weak var value: T…

---

## [Swift compiler crashes by generics / missing conformance](https://forums.swift.org/t/swift-compiler-crashes-by-generics-missing-conformance/81677)

<div class="topic-metadata">

**Author:** [@nesrve](https://forums.swift.org/u/nesrve)\
**Replies:** 1\
**Last updated:** [August 17, 2025, 1:15am UTC](https://forums.swift.org/t/swift-compiler-crashes-by-generics-missing-conformance/81677 "2025-08-17T01:15:09Z")

</div>

struct Foo\<T\> {} struct Bar {} let foo = Foo\<Bar\>() let foos: Set\<Foo\> = \[foo\] trying to run this crashes the compiler. the code snippet above is an attempt from me to get a minimal reproduction of the code that cause…

---

## [Understanding protocols + any, & how to switch to concrete types](https://forums.swift.org/t/understanding-protocols-any-how-to-switch-to-concrete-types/81588)

<div class="topic-metadata">

**Author:** [@tishly](https://forums.swift.org/u/tishly)\
**Replies:** 5\
**Last updated:** [August 13, 2025, 12:59pm UTC](https://forums.swift.org/t/understanding-protocols-any-how-to-switch-to-concrete-types/81588 "2025-08-13T12:59:30Z")

</div>

Premise I’m currently trying to build out a SwiftUI View to display cells of various sizes, each containing some content view struct that I want to additionally conform to a custom protocol. Container Views will hold th…

---

## [Generics with diffable data source for multiple sections / cell types](https://forums.swift.org/t/generics-with-diffable-data-source-for-multiple-sections-cell-types/81269)

<div class="topic-metadata">

**Author:** [@gs1221xy](https://forums.swift.org/u/gs1221xy)\
**Replies:** 2\
**Last updated:** [July 24, 2025, 9:41am UTC](https://forums.swift.org/t/generics-with-diffable-data-source-for-multiple-sections-cell-types/81269 "2025-07-24T09:41:52Z")

</div>

Hi guys. I am trying to implement collection view screen with multiple sections and cell types using diffable data source. I define it using Sections enum and SectionItem struct which keeps nested model for cells config…

[Next page](https://forums.swift.org/tag/protocols/86.md?match_all_tags=true&page=1&tags%5B%5D=protocols)
