Swiftpack.co - Package - lukaskubanek/OrderedDictionary


OrderedDictionary is a lightweight implementation of an ordered dictionary data structure in Swift.

The OrderedDictionary struct is a generic collection which combines the features of Dictionary and Array from the Swift standard library. Like Dictionary it stores key-value pairs with each key being unique and maps each key to an associated value. Like Array it stores those pairs sorted and accessible by a zero-based integer index.

OrderedDictionary provides similar APIs like collections from the Swift standard library. This includes accessing contents by keys or indices, inserting and removing elements, iterating, sorting etc.

Internally, OrderedDictionary uses a backing store composed of an instance of Dictionary for storing the key-value pairs and an instance of Array for managing the ordered keys. This means it is not the most performant implementation possible, but it gets its job done by reusing most functionality from the Swift standard library.


  • Swift 4.0+ (4.0, 4.2, 5.0, 5.1)
  • Xcode 9.2+
  • iOS 8.0+ / macOS 10.10+


The library is distributed as a Swift framework and can be integrated into your project in following ways:


If you use Carthage for managing your dependencies, put OrderedDictionary into your Cartfile:

github "lukaskubanek/OrderedDictionary"

Then, drag either the OrderedDictionary.xcodeproj or the OrderedDictionary.framework into your project/workspace and link your target against the OrderedDictionary.framework. Also make sure that the framework gets copied to your application bundle.

Swift Package Manager

Another option is to use the Swift Package Manager. If you prefer this option, put OrderedDictionary as a dependency to your Package.swift:

.package(url: "https://github.com/lukaskubanek/OrderedDictionary.git", from: "2.3.0")

Git Submodules

Yet another option is using Git submodules and integrating the Xcode project OrderedDictionary.xcodeproj from the submodule directly to your Xcode workspace.

⚠️ Note About CocoaPods

Although there is high demand for CocoaPods support, this method won't be officially supported by this library. Since I'm not using CocoaPods myself and since I think this method will be once replaced by the Swift Package Manager, I don't want to put any effort in maintaining an official podspec. If you really want to include this library via CocoaPods, there is still a way by creating a custom podspec (see the last section of this post).

Usage & Docs

For the usage of this library please refer to the example playground. For documentation please refer to the documentation comments.


The changelog is managed on the GitHub releases page.


Lukas Kubanek // lukaskubanek.com // @kubanekl


OrderedDictionary is provided under the MIT License.


Stars: 124
Help us keep the lights on


Used By



v2.3.0 - Jul 30, 2019

  • Introduced mapValues(_:) & compactMapValues(_:)
  • Renamed initializers to better convey their semantics
    • init(_:)init(uniqueKeysWithValues:)
    • init(values:keyedBy:)init(values:uniquelyKeyedBy:)
    • Added shims for the deprecated versions
  • Fixed warnings for Swift 5.0

v2.2.2 - Apr 29, 2019

In version 2.2.1 I accidentally forgot to bump the version numbers. This is now fixed in this further patch release.

v2.2.1 - Apr 29, 2019

This patch should address the issue with package definition format reported in #51.

v2.2.0 - Apr 4, 2019

  • Added support for Swift 5.0 by making changes necessary for Xcode 10.2
  • This version should still work with Swift 4.0 & 4.2
  • Fixed an issue with reset flag for marking the code as safe for app extensions [#10, #50] (thanks to @graphiclife)

v2.1.0 - Jul 10, 2018

  • Added support for Swift Package Manager (thanks to @jnordberg)
  • Optimized lookup performace (thanks to @maicki)
  • Introduced Dictionary.sorted(by:)
  • Introduced popFirst(), popLast(), removeFirst(), removeLast() methods
  • Annotated sort methods with throws/rethrows keywords
  • Added note about no support for CocoaPods