CocoaPods trunk is moving to be read-only. Read more on the blog, there are 11 months to go.

SwiftlyExt 1.3.0

SwiftlyExt 1.3.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Khoi Lai.



  • By
  • Khoi Lai

SwiftlyExt is a library that extends certain Swift standard types and classes using extension feature in the Swift language.

Requirements

  • iOS 9.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 8.0+
  • Swift 3.0+

Installation

Swift Package Manager

Adding SwiftlyExt as a dependency is as easy as adding it to the dependencies value of your Package.swift file.

dependencies: [
    .Package(url: "https://github.com/khoiln/SwiftlyExt.git", majorVersion: 1)
]

Note that the Swift Package Manager is still in early design and development, but SwiftlyExt does support its use on supported platforms.

Usage

There are many handy usages of SwiftlyExt, head over CocoaDocs for the comprehensive documentation.

We’ll try to list some of the cool examples here.

Array Extensions

// Return a random element
[😀,🤡,❤️,💋].sample() // => 💋
// Return n random elements
[😀,🤡,❤️,💋].sampleSize(2) // => [🤡, 💋]
//Drop elements that passes the predicate from the beginning to end
[1, 2, 3, 4, 5].dropWhile { $0 < 3 } // => [3, 4, 5]
//And YES you can use method chaining too 👍
[1, 2, 3, 4, 5].dropWhile { $0 < 3 }.some {$0 % 2 == 0} // => true
//Check if all elements in the array passed the condition
[0, 11, 28, 10].every { $0 % 2 == 0 } // => false
//Check if one of the element passes the condition
[0, 11, 28, 10].some { $0 % 2 != 0 } // => true
//Find index of the last number which predicate return true for.
[1, 2, 3, 4, 5].findLastIndex {$0 % 2 == 0} // => 3 
//Group common elements from an array to a dictionary of [Hashable : [Element]]
[1, 2, 3, 4, 5].groupBy { $0 % 2 == 0 ? "even" : "odd"} // => ["even": [2,4], "odd": [1,3,5]]

How to contribute

Any help or feedback is highly appreciated. Please refer to the contributing guidelines for more information.

License

SwiftyExt is released under the MIT license. See LICENSE for details.