# \#collection

**URL:** https://forums.swift.org/tag/collection/13.md

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

---

## [CRLFSequence](https://forums.swift.org/t/crlfsequence/90124)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 0\
**Last updated:** [October 17, 2026, 12:22am UTC](https://forums.swift.org/t/crlfsequence/90124 "2026-10-17T00:22:26Z")

</div>

I needed to read and write CR-LF strings. Instead of simply creating a \[13, 10\] array on the spot, I wanted to centralize the concept. It's at https://gitlab.com/ctmacuser/CRLFSequence.

---

## [Future of ~Escapable for Slices](https://forums.swift.org/t/future-of-escapable-for-slices/89800)

<div class="topic-metadata">

**Author:** [@Dmitriy\_Ignatyev](https://forums.swift.org/u/Dmitriy_Ignatyev)\
**Replies:** 3\
**Last updated:** [October 2, 2026, 4:46pm UTC](https://forums.swift.org/t/future-of-escapable-for-slices/89800 "2026-10-02T16:46:18Z")

</div>

Hi everyone With the recent advancements in Swift’s ownership model, specifically the introduction of ~Escapable types, we now have a robust system for compile-time lifetime control. This got me thinking about the seman…

---

## [A memory-saving type for Collections of Strings](https://forums.swift.org/t/a-memory-saving-type-for-collections-of-strings/88299)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 2\
**Last updated:** [July 23, 2026, 11:51pm UTC](https://forums.swift.org/t/a-memory-saving-type-for-collections-of-strings/88299 "2026-07-23T23:51:42Z")

</div>

I made a pull request for a new Collection type. Like many containers with variable element counts, String stores its character data in a dynamic memory block. Since the standard collections do the same thing, a collecti…

---

## [Copy-on-write behaviour of collection types](https://forums.swift.org/t/copy-on-write-behaviour-of-collection-types/88184)

<div class="topic-metadata">

**Author:** [@EndBird](https://forums.swift.org/u/EndBird)\
**Replies:** 2\
**Last updated:** [July 10, 2026, 12:53am UTC](https://forums.swift.org/t/copy-on-write-behaviour-of-collection-types/88184 "2026-07-10T00:53:17Z")

</div>

In docs, it says “Collections defined by the Swift standard library like arrays, dictionaries, and strings use an optimization to reduce the performance cost of copying. Instead of making a copy immediately, these collec…

---

## [How can I use the Swift Collections package with a compile-time flag?](https://forums.swift.org/t/how-can-i-use-the-swift-collections-package-with-a-compile-time-flag/83800)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 2\
**Last updated:** [April 1, 2026, 10:28pm UTC](https://forums.swift.org/t/how-can-i-use-the-swift-collections-package-with-a-compile-time-flag/83800 "2026-04-01T22:28:36Z")

</div>

I want to try out a new type that uses the secret sorted collections from the Swift Collection library. I get errors that “SortedSet cannot be found in scope.” I just tweaked the Package.swift that was initially generate…

---

## [\[Pitch\] Rule\<T: Collection\> — A Composable Pattern Recognizer for any Collection](https://forums.swift.org/t/pitch-rule-t-collection-a-composable-pattern-recognizer-for-any-collection/85492)

<div class="topic-metadata">

**Author:** [@MaximilianServais](https://forums.swift.org/u/MaximilianServais)\
**Replies:** 38\
**Last updated:** [March 29, 2026, 7:03pm UTC](https://forums.swift.org/t/pitch-rule-t-collection-a-composable-pattern-recognizer-for-any-collection/85492 "2026-03-29T19:03:09Z")

</div>

Pitch: Rule\<T: Collection\> — A Composable Pattern Recognizer for any Collection Introduction I would like to pitch a new standard library type, Rule\<T: Collection\>, a universal, composable pattern recognizer for any Swif…

---

## [Swift-async-collections](https://forums.swift.org/t/swift-async-collections/85312)

<div class="topic-metadata">

**Author:** [@SerhanAksut](https://forums.swift.org/u/SerhanAksut)\
**Replies:** 1\
**Last updated:** [March 13, 2026, 8:10am UTC](https://forums.swift.org/t/swift-async-collections/85312 "2026-03-13T08:10:08Z")

</div>

Hi everyone, I'd like to share AsyncCollections - a lightweight package that adds async and concurrent higher-order functions to Swift's Sequence type. Motivation Running async work over a regular Array typically mean…

---

## [Casting closure collections](https://forums.swift.org/t/casting-closure-collections/82100)

<div class="topic-metadata">

**Author:** [@Nickolas\_Pohilets](https://forums.swift.org/u/Nickolas_Pohilets)\
**Replies:** 11\
**Last updated:** [November 4, 2025, 9:22am UTC](https://forums.swift.org/t/casting-closure-collections/82100 "2025-11-04T09:22:42Z")

</div>

I'm working on a fix for #82618. For us this is a blocker for incremental Swift 6 adoption, but it also reproduces without concurrency features. The bug can be fixed in different ways: Rejecting the code with an compi…

---

## [Protocol as Dictionary Key or Set element](https://forums.swift.org/t/protocol-as-dictionary-key-or-set-element/80075)

<div class="topic-metadata">

**Author:** [@brustolin](https://forums.swift.org/u/brustolin)\
**Replies:** 17\
**Last updated:** [May 27, 2025, 1:44pm UTC](https://forums.swift.org/t/protocol-as-dictionary-key-or-set-element/80075 "2025-05-27T13:44:29Z")

</div>

Can someone explain to me the problem of having a protocol that implements Hashable as a dictionary key or as the element of a set? like protocol MyProtocol: Hashable { var id: Int { get } } Any type that implemen…

---

## [Can anyone glance over this \`FourCharCode\` wrapper?](https://forums.swift.org/t/can-anyone-glance-over-this-fourcharcode-wrapper/79266)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 1\
**Last updated:** [April 15, 2025, 3:33am UTC](https://forums.swift.org/t/can-anyone-glance-over-this-fourcharcode-wrapper/79266 "2025-04-15T03:33:21Z")

</div>

I ended up wrapping the Foundation type FourCharCode so I can manage its values better (in a Swift-y way). It's at: https://github.com/CTMacUser/ClassicFourCharCode and I made a "0.1.0" tag. I put in every applicable s…

---

## [Is there a testing suite for Collection types out there?](https://forums.swift.org/t/is-there-a-testing-suite-for-collection-types-out-there/79236)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 0\
**Last updated:** [April 11, 2025, 6:40pm UTC](https://forums.swift.org/t/is-there-a-testing-suite-for-collection-types-out-there/79236 "2025-04-11T18:40:30Z")

</div>

My type conforms to all the conventional Collection protocols except RangeReplaceableCollection. The suite should indirectly test the secret Sequence/Collection requirements too.

---

## [How do I finalize this collection package?](https://forums.swift.org/t/how-do-i-finalize-this-collection-package/78972)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 1\
**Last updated:** [March 31, 2025, 5:51pm UTC](https://forums.swift.org/t/how-do-i-finalize-this-collection-package/78972 "2025-03-31T17:51:13Z")

</div>

I made a package here: https://github.com/CTMacUser/EmbeddedIntegerCollection.git I'm wondering two things: For the MutableCollection support, I wrote my own read-write single-element subscript operator. I just let t…

---

## [The wrong default \`Indices\` type is being used](https://forums.swift.org/t/the-wrong-default-indices-type-is-being-used/78598)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 4\
**Last updated:** [March 19, 2025, 5:35am UTC](https://forums.swift.org/t/the-wrong-default-indices-type-is-being-used/78598 "2025-03-19T05:35:51Z")

</div>

I thought if you define a Collection type, but don't explicitly provide a Indices type, the default will be DefaultIndices. Instead, I got Range\<Int\>, which is bad since it uses a spacing of 1, which my type doesn't use.…

---

## [Using \`index(\_:offsetBy:limitedBy:)\` at the limit](https://forums.swift.org/t/using-index-limitedby-at-the-limit/78564)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 0\
**Last updated:** [March 16, 2025, 11:21pm UTC](https://forums.swift.org/t/using-index-limitedby-at-the-limit/78564 "2025-03-16T23:21:07Z")

</div>

If the starting index is already at the border index, and the offset distance isn't 0, then this method should return nil, right? The description mentions the limit having no effect if it's in the wrong direction, but it…

---

## [Efficiently Reaping Weak Collections](https://forums.swift.org/t/efficiently-reaping-weak-collections/78205)

<div class="topic-metadata">

**Author:** [@bdkjones](https://forums.swift.org/u/bdkjones)\
**Replies:** 7\
**Last updated:** [March 1, 2025, 10:25pm UTC](https://forums.swift.org/t/efficiently-reaping-weak-collections/78205 "2025-03-01T22:25:17Z")

</div>

Context: I have a ModelController that keeps a collection of weak references to ModelObjects. The controller receives changes from the cloud and, for each one, sees if the change affects a ModelObject in the collection. …

---

## [\[Pitch\] Add Collection conformance for EnumeratedSequence](https://forums.swift.org/t/pitch-add-collection-conformance-for-enumeratedsequence/76680)

<div class="topic-metadata">

**Author:** [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Replies:** 0\
**Last updated:** [December 16, 2024, 9:26pm UTC](https://forums.swift.org/t/pitch-add-collection-conformance-for-enumeratedsequence/76680 "2024-12-16T21:26:29Z")

</div>

Hello Evolution, this is a very targeted revision of SE-0312 Add indexed() and Collection conformances for enumerated() and zip(::) for just the collection conformances for EnumeratedSequence . Add Collection conformanc…

---

## [Checking equality of key paths not working as I expected](https://forums.swift.org/t/checking-equality-of-key-paths-not-working-as-i-expected/76594)

<div class="topic-metadata">

**Author:** [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Replies:** 2\
**Last updated:** [December 13, 2024, 2:18pm UTC](https://forums.swift.org/t/checking-equality-of-key-paths-not-working-as-i-expected/76594 "2024-12-13T14:18:07Z")

</div>

I ran into somewhat unexpected behavior when trying to compare key paths for equality. My best guess is that the key path that I'm passing into the doSomething(with:) method references the concrete type's implementation,…

---

## [\[Pitch\] AttributedString Discontiguous Operations](https://forums.swift.org/t/pitch-attributedstring-discontiguous-operations/76574)

<div class="topic-metadata">

**Author:** [@jmschonfeld](https://forums.swift.org/u/jmschonfeld)\
**Replies:** 0\
**Last updated:** [December 12, 2024, 6:15pm UTC](https://forums.swift.org/t/pitch-attributedstring-discontiguous-operations/76574 "2024-12-12T18:15:02Z")

</div>

Hi everyone! In addition to other recent AttributedString APIs that I've pitched, I'd also like to pitch new APIs for AttributedString to support operations over discontiguous subranges. These APIs mirror those introduce…

---

## [\[Pitch\] Add \`insertOrRemove(\_:)\` Method to \`Set\` and \`SetAlgebra\` in Swift](https://forums.swift.org/t/pitch-add-insertorremove-method-to-set-and-setalgebra-in-swift/76215)

<div class="topic-metadata">

**Author:** [@Rspoon3](https://forums.swift.org/u/Rspoon3)\
**Replies:** 27\
**Last updated:** [December 9, 2024, 7:16pm UTC](https://forums.swift.org/t/pitch-add-insertorremove-method-to-set-and-setalgebra-in-swift/76215 "2024-12-09T19:16:25Z")

</div>

Introduction This proposal suggests adding an insertOrRemove(\_:) method to the SetAlgebra protocol in Swift, and by extension to the Set type. This method provides a concise and intuitive way to toggle the presence of an…

---

## [Adding a LinkedList type to the Standard Library](https://forums.swift.org/t/adding-a-linkedlist-type-to-the-standard-library/32339)

<div class="topic-metadata">

**Author:** [@Wildchild9](https://forums.swift.org/u/Wildchild9)\
**Replies:** 24\
**Last updated:** [October 5, 2024, 5:13pm UTC](https://forums.swift.org/t/adding-a-linkedlist-type-to-the-standard-library/32339 "2024-10-05T17:13:18Z")

</div>

Swift is missing a great many data types (see Adding more data structures to the standard library). I thought I may be able to get this going with suggesting the introduction of a LinkedList type to Swift. Linked lists …

---

## [I did end up making a FNV class. Now what?](https://forums.swift.org/t/i-did-end-up-making-a-fnv-class-now-what/73582)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 1\
**Last updated:** [July 31, 2024, 12:02am UTC](https://forums.swift.org/t/i-did-end-up-making-a-fnv-class-now-what/73582 "2024-07-31T00:02:57Z")

</div>

Continuing the discussion from How are the tags for an overloaded function in DoCC/Markdown generated?: I did end up making a Sequence extension that adds an FNV hashing function. I haven't uploaded it yet. I'm wonderin…

---

## [Can't the striding function's return types conform to Collection now?](https://forums.swift.org/t/cant-the-striding-functions-return-types-conform-to-collection-now/40004)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 5\
**Last updated:** [July 27, 2024, 6:03pm UTC](https://forums.swift.org/t/cant-the-striding-functions-return-types-conform-to-collection-now/40004 "2024-07-27T18:03:53Z")

</div>

The return types for stride(from: to: by:) and stride(from: through: by:), StrideTo and StrideThrough respectively, are only Sequences, not Collections. This was caused by a bug in conditional conformance, as mentioned …

---

## [Using 'filter' on an array of actors](https://forums.swift.org/t/using-filter-on-an-array-of-actors/73386)

<div class="topic-metadata">

**Author:** [@maartene](https://forums.swift.org/u/maartene)\
**Replies:** 4\
**Last updated:** [July 23, 2024, 7:27pm UTC](https://forums.swift.org/t/using-filter-on-an-array-of-actors/73386 "2024-07-23T19:27:06Z")

</div>

Hi everyone, I have a function that filters an array of Actors: actor Entity { // other stuff var state: State { // determine state } } actor World { // other stuff let entities: \[Entity\] …

---

## [I forgot how to convert a reversed-collection index to its original index](https://forums.swift.org/t/i-forgot-how-to-convert-a-reversed-collection-index-to-its-original-index/73160)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 2\
**Last updated:** [July 14, 2024, 8:12am UTC](https://forums.swift.org/t/i-forgot-how-to-convert-a-reversed-collection-index-to-its-original-index/73160 "2024-07-14T08:12:34Z")

</div>

I forgot, if you have the index of an element in a reversed collection, how do you get the element's index in its original collection? I haven't messed with those for years; and I always got semi-confused which way it go…

---

## [Tree: A hierarchical tree structure for Swift](https://forums.swift.org/t/tree-a-hierarchical-tree-structure-for-swift/70095)

<div class="topic-metadata">

**Author:** [@mattcox](https://forums.swift.org/u/mattcox)\
**Replies:** 0\
**Last updated:** [February 16, 2024, 8:57pm UTC](https://forums.swift.org/t/tree-a-hierarchical-tree-structure-for-swift/70095 "2024-02-16T20:57:21Z")

</div>

Hi Everyone, I thought I'd share a package that I wrote a few months ago. Compared to a lot of the packages shared here, this one is pretty simple, but it has proved quite useful in my projects. Tree is a Swift packa…

---

## [\[Accepted\] SE-0270: Add \`Collection\` operations on noncontiguous elements](https://forums.swift.org/t/accepted-se-0270-add-collection-operations-on-noncontiguous-elements/69080)

<div class="topic-metadata">

**Author:** [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Replies:** 0\
**Last updated:** [December 20, 2023, 12:41am UTC](https://forums.swift.org/t/accepted-se-0270-add-collection-operations-on-noncontiguous-elements/69080 "2023-12-20T00:41:04Z")

</div>

Hello, everyone. The fourth review of SE-0270: Add Collection operations on noncontiguous elements ran from December 6th through the 18th. This review was both a re-review of the old proposal as part of accepting it in…

---

## [SE-0270 (fourth review): Add Collection operations on noncontiguous elements](https://forums.swift.org/t/se-0270-fourth-review-add-collection-operations-on-noncontiguous-elements/68855)

<div class="topic-metadata">

**Author:** [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Replies:** 21\
**Last updated:** [December 20, 2023, 12:41am UTC](https://forums.swift.org/t/se-0270-fourth-review-add-collection-operations-on-noncontiguous-elements/68855 "2023-12-20T00:41:53Z")

</div>

Hello, Swift community. SE-0270 was originally reviewed in a series of reviews beginning in late 2019 and accepted into the Preview package in January 2020. The proposal authors have decided that they would like to grad…

---

## [Closure return value seemingly affecting execution of unrelated expressions](https://forums.swift.org/t/closure-return-value-seemingly-affecting-execution-of-unrelated-expressions/69042)

<div class="topic-metadata">

**Author:** [@mattwylder](https://forums.swift.org/u/mattwylder)\
**Replies:** 4\
**Last updated:** [December 17, 2023, 11:41pm UTC](https://forums.swift.org/t/closure-return-value-seemingly-affecting-execution-of-unrelated-expressions/69042 "2023-12-17T23:41:34Z")

</div>

Hi all, I'm running in to a really strange issue using filtering on a collection. It seems that its code execution within a closure is dependent on the return value of the closure. I am writing a script to iterate thro…

---

## [Compiler optimisations for functional-style Collection algorithms](https://forums.swift.org/t/compiler-optimisations-for-functional-style-collection-algorithms/68291)

<div class="topic-metadata">

**Author:** [@wadetregaskis](https://forums.swift.org/u/wadetregaskis)\
**Replies:** 20\
**Last updated:** [November 14, 2023, 7:39pm UTC](https://forums.swift.org/t/compiler-optimisations-for-functional-style-collection-algorithms/68291 "2023-11-14T19:39:13Z")

</div>

I'm exploring Swift's performance in some basic situations involving operations on Collections and Sequences. As part of that, I've been benchmarking the difference between programming styles (using simple, contrived al…

---

## [Can a group of weak references conform to Collection?](https://forums.swift.org/t/can-a-group-of-weak-references-conform-to-collection/65899)

<div class="topic-metadata">

**Author:** [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Replies:** 4\
**Last updated:** [June 30, 2023, 7:32am UTC](https://forums.swift.org/t/can-a-group-of-weak-references-conform-to-collection/65899 "2023-06-30T07:32:00Z")

</div>

I have a type that collects weak references, which you can iterate over and append to. I want it to conform to RangeReplaceableCollection, but I don't think I can do anything more specific than Sequence. The type itself…

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