SwiftyCollection 1.0.6

SwiftyCollection 1.0.6

Alex HmelevskiAlex HmelevskiPiyush Sharma 维护。



  • ALDO Inc

SwiftyCollection

CircleCI Version License Platform

描述

该库为 Collection 协议家族(Collection、MutableCollection 和 RangeReplacableCollection)提供了扩展,以简化并对元素进行范围安全的访问。添加的大部分函数返回可选类型,其中 .none 用于代替传统的致命错误。

Collection 方法

  • func element(at index: Index) -> Element?
  • func indexInBounds(_ index: Index) -> Bool

可变范围可替换 Collection 方法

  • mutating func removeLastSafe() -> SubSequence.Element?
  • mutating func removeFirstSafe() -> SubSequence.Element?
  • mutating func replaceOccurrences(with element: Element, where predicate: (Element) -> Bool)
  • mutating func removeElement(where predicate: (Element) -> Bool) -> Self.Element?

具有可变属性的RangeReplaceableCollection集合方法与可比较元素

  • mutating func replaceOccurrences(of element: Element, with newElement: Element)
  • mutating func removeElement(element: Element) -> Self.Element?
  • mutating func removeElement(at index: Self.Index) -> Self.Element?
  • mutating func removeDuplicates()

RangeReplaceableCollection

这些函数将返回一个新的集合

  • func removingLast() -> Self
  • func removingFirst() -> Self
  • func removingElement(where predicate: (Element) -> Bool) -> Self
  • func replacingOccurrences(with newElement: Element, where predicate: (Element) -> Bool) -> Self
  • func replacing(with newElement: Element, at index: Self.Index) -> Self
  • func removing(at index: Self.Index) -> Self

RangeReplaceableCollection与可比较元素的演化

  • func removingElement(_ element: Element) -> Self
  • func replacingOccurrences(of element: Element, with newElement: Element ) -> Self
  • func removingDuplicates() -> Self

示例

要运行示例项目,请先克隆存储库,然后从 Example 目录运行 pod install

安装

SwiftyCollection可通过CocoaPods获取。要安装它,只需将以下行添加到您的 Podfile 中即可。

pod 'SwiftyCollection'

作者

ALDO Inc.,[email protected]

许可证

SwiftyCollection遵循MIT协议。详细信息请查阅LICENSE文件。