Swift Collections is an open-source package of data structure implementations for Swift, offered in stable modules with optional experimental traits.
Overview
Swift Collections supplies typed containers beyond the standard library: deques, ordered sets and dictionaries, bit sets and arrays, heaps, persistent hash trees, ownership-aware arrays and boxes, and related low-level utilities. A single Collections import re-exports the stable modules for everyday use.
Stable modules include BasicContainers, DequeModule, OrderedCollections, BitCollections, HeapModule, HashTreeCollections, TrailingElementsModule, and ContainersPreview pieces that are declared public. Experimental package traits gate sorted collections, hashed container previews, and container protocol previews that may change without notice.
The maintainers treat semantic versioning on the public API seriously: only non-underscored public declarations in listed modules without traits form the compatibility promise. New minor releases may require newer Swift toolchains, documented in a version-to-toolchain table in the project materials.
Key features
- Deque and rigid or unique deque types
- Insertion-ordered set and dictionary
- BitSet and BitArray implementations
- Min-max heap priority queue
- Persistent TreeSet and TreeDictionary
- Ownership-aware UniqueArray and RigidArray
- Single-module Collections import
- Opt-in experimental package traits
Use cases
- Deque-based queues in Swift apps
- Deterministic iteration order maps
- Compact bit set storage
- Priority queues via Heap
- Persistent structures with shared copies