Skip to content

A Swift collection of unique, ordered objects

License

Notifications You must be signed in to change notification settings

FBente/OrderedSet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

OrderedSet is essentially the Swift equivalent of Foundation's NSOrderedSet/NSMutableOrderedSet. It was created so Swift would have a unique, ordered collection with fast lookup performance that supported strong typing through Generics, and so we could store Swift structs and enums in it.

Usage

OrderedSet works very much like an Array. Here are some basic examples of its usage:

var set = OrderedSet<Int>()
set.append(1)
set.contains(1) // => true
set[0] = 2
set[0] // => 2
set.insertObject(3, atIndex: 0)
set // => [3, 2]
set = [1,2,3] // OrderedSet's support array literals
set // => [1, 2, 3]
set += [3, 4] // You can concatenate any sequence type to an OrderedSet
set // => [1, 2, 3, 4] (Since 3 was already in the set it was not added again)

Its also recommended that you use the instance methods when possible instead of the global Swift methods for searching an OrderedSet. For example, the Swift.contains(haystack, needle) method will enumerate the OrderedSet instead of making use of the fast lookup implementation that the OrderedSet.contains(needle) method will do.

Be sure to check out the unit tests to see all the different ways to interact with an OrderedSet in action. You can also check out the sample project, which tweaks the default master/detail project to use an OrderedSet instead of an Array.

Installation

OrderedSet is a single Swift file in the Sources directory. You can copy that file into your project, or use CocoaPods by adding the following line to your Podfile:

pod 'OrderedSet', '1.0'

And then add the following import where you want to use OrderedSet:

import OrderedSet

License

OrderedSet is available under the MIT license. See the LICENSE file for more info.

CONTRIBUTING

We love to have your help to make OrderedSet better. Feel free to

  • open an issue if you run into any problem.
  • fork the project and submit pull request.

About

A Swift collection of unique, ordered objects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 97.3%
  • Ruby 2.7%