Latest 0.1.7
Homepage https://github.com/bemindinteractive/SwiftSortedList
License MIT
Platforms ios 8.0
Authors

Version
License
Platform

Usage

All you need is a Comparable object:

import SwiftSortedList

struct MyObj : Comparable {
    var id: Int
}

func ==(x: MyObj, y: MyObj) -> Bool {
    return x.id == y.id
}
func <(x: MyObj, y: MyObj) -> Bool {
    return x.id < y.id
}

Then you can use the SortedList:

// create a new sorted list

var sl = SortedList<MyObj>()

// add an object

let mo = MyObj(id: 1)
sl.addElement(mo)

// get an object

let mo2 = sl.getAt(0)
let mo2s = sl[0]
print(mo2 == mo2s)

// helpers functions

let size: Int = sl.count
let elements: [MyObj] = sl.array

// remove an object

sl.removeElement(mo)

// replace an object
let mo3 = MyObj(id: 3)
sl.replace(at: 0, with: mo3)
print(mo2 == sl[0]) // false
print(mo3 == sl[0]) // true

// loop

for el in sl.array {
    // do something with el
}

Installation

SwiftSortedList is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "SwiftSortedList"

Author

Alessandro Miliucci

License

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

Latest podspec

{
    "name": "SwiftSortedList",
    "version": "0.1.7",
    "summary": "A sorted list implementation for Swift.",
    "description": "A sorted list implementation for Swift. See the README for more info.",
    "homepage": "https://github.com/bemindinteractive/SwiftSortedList",
    "license": "MIT",
    "authors": {
        "Alessandro Miliucci": "[email protected]"
    },
    "source": {
        "git": "https://github.com/bemindinteractive/SwiftSortedList.git",
        "tag": "0.1.7"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "SwiftSortedList/Classes/**/*",
    "resource_bundles": {
        "SwiftSortedList": [
            "SwiftSortedList/Assets/*.png"
        ]
    }
}

Pin It on Pinterest

Share This