SwiftSortedList 0.1.7

SwiftSortedList 0.1.7

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2016年5月
SPM支持 SPM

Alessandro Miliucci 维护。



  • 作者:
  • Alessandro Miliucci

SwiftSortedList

使用方法

您只需要一个可比较的对象

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
}

然后您可以使用 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
}

安装

通过 CocoaPods 可用 SwiftSortedList。要安装它,只需在 Podfile 中添加以下行:

pod "SwiftSortedList"

作者

Alessandro Miliucci

许可证

SwiftSortedList 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。