Skip to content

A set of Swift extensions for standard types and classes.

License

Notifications You must be signed in to change notification settings

ColinEberhardt/ExSwift

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExSwift

JavaScript (Lo-Dash, Underscore) & Ruby inspired set of Swift extensions for standard types and classes.

Contents

Extensions

Array

Examples in the Wiki

Instance Methods

Name Signature
first first () -> Element?
last last () -> Element?
get get (index: Int) -> Element?
remove remove <U: Equatable> (element: U)
at at (indexes: Int...) -> Array
take take (n: Int) -> Array
takeWhile takeWhile (condition: (Element) -> Bool) -> Array
tail tail (n: Int) -> Array
skip skip (n: Int) -> Array
skipWhile skipWhile (condition: (Element) -> Bool) -> Array
contains contains <T: Equatable> (item: T...) -> Bool
difference difference <T: Equatable> (values: Array<T>...) -> Array<T>
intersection intersection <U: Equatable> (values: Array<U>...) -> Array
union union <U: Equatable> (values: Array<U>...) -> Array
unique unique <T: Equatable> () -> Array<T>
indexOf indexOf <T: Equatable> (item: T) -> Int?
lastIndexOf lastIndexOf <T: Equatable> (item: T) -> Int?
zip zip (arrays: Array<Any>...) -> Array<Array<Any?>>
partition partition (var n: Int, var step: Int? = nil) -> Array<Array<Element>>
partition (var n: Int, var step: Int? = nil, pad: Element[]?) -> Array<Array<Element>>
partitionAll partitionAll (var n: Int, var step: Int? = nil) -> Array<Array<Element>>
partitionBy partitionBy <T: Equatable> (cond: (Element) -> T) -> Array<Array<Element>>
shuffle shuffle ()
shuffled shuffled () -> Array
sample (random) sample (size n: Int = 1) -> Array<T>
max max <T: Comparable> () -> T
min min <T: Comparable> () -> T
each each (call: (Element) -> ())
each (call: (Int, Element) -> ())
eachRight eachRight (call: (Element) -> ())
eachRight (call: (Int, Element) -> ())
any any (call: (Element) -> Bool) -> Bool
all all (call: (Element) -> Bool) -> Bool
reject reject (exclude: (Element -> Bool)) -> Array
pop pop() -> Element
push push(newElement: Element)
shift shift() -> Element
unshift unshift(newElement: Element)
groupBy groupBy <U> (groupingFunction group: (Element) -> (U)) -> Dictionary<U, Array>
countBy countBy <U> (groupingFunction group: (Element) -> (U)) -> Dictionary<U, Int>
reduceRight reduceRight <U>(initial: U, combine: (U, Element) -> U) -> U
implode implode <C: ExtensibleCollection> (separator: C) -> C?
flatten flatten <OutType> () -> OutType[]
sortBy sortBy (isOrderedBefore: (T, T) -> Bool) -> Array<T>
toDictionary toDictionary <U> (keySelector:(Element) -> U) -> Dictionary<U, Element>

Class Methods

Name Signatures
range range <U: ForwardIndex> (range: Range<U>) -> Array<U>

Operators

Name Signature Function
- - <T: Equatable> (first: Array<T>, second: Array<T>) -> Array<T> Difference
- - <T: Equatable> (first: Array<T>, second: T) -> Array<T> Element removal
& & <T: Equatable> (first: Array<T>, second: Array<T>) -> Array<T> Intersection
| | <T: Equatable> (first: Array, second: Array) -> Array Union
* Int * <ItemType> (array: ItemType[], n: Int) -> ItemType[] Returns a new array built by concatenating int copies of self
* String * (array: String[], separator: String) -> String Equivalent to array.implode(String)
[x..y]
[x...y]
subscript(range: Range<Int>) -> Array Returns the sub-array from index x to index y
[x, y, ...] subscript(first: Int, second: Int, rest: Int...) -> Array Returns the items at x, y

Int

Examples in the Wiki

Instance Methods

Name Signatures
times times <T> (call: (Int) -> T)
times <T> (call: () -> T)
times (call: () -> ())
isEven isEven () -> Bool
isOdd idOdd () -> Bool
upTo upTo (limit: Int, call: (Int) -> ())
downTo downTo (limit: Int, call: (Int) -> ())
clamp clamp (range: Range<Int>) -> Int
clamp (min: Int, max: Int) -> Int
isIn isIn (range: Range<Int>, strict: Bool = false) -> Bool
digits digits () -> Array<Int>
abs abs () -> Int
gcd gcd (n: Int) -> Int
lcm lcm (n: Int) -> Int

Class Methods

Name Signatures
random random(min: Int = 0, max: Int) -> Int

Float

Examples in the Wiki

Instance Methods

Name Signature
abs abs () -> Float
sqrt sqrt () -> Float
round round () -> Float
ceil ceil () -> Float
floor floor () -> Float
digits digits () -> (integerPart: Int[], fractionalPart: Int[])

Class Methods

Name Signatures
random random(min: Float = 0, max: Float) -> Float

String

Examples in the Wiki

Properties

Name
length

Instance Methods

Name Signature
explode explode (separator: Character) -> String[]
at at (indexes: Int...) -> String[]
matches matches (pattern: String, ignoreCase: Bool = false) -> NSTextCheckingResult[]?
capitalized capitalized () -> String
insert insert (index: Int, _ string: String) -> String
ltrimmed ltrimmed () -> String
rtrimmed rtrimmed () -> String
trimmed trimmed () -> String

Class Methods

Name Signature
random func random (var length len: Int = 0, charset: String = "...") -> String

Operators

Name Signature
[x] subscript(index: Int) -> String?
[x..y]
[x...y]
subscript(range: Range<Int>) -> String
[x, y, z] subscript (indexes: Int...) -> String[]
S * n * (first: String, second: Int) -> String
=~ =~ (string: String, pattern: String) -> Bool
=~ (string: String, options: (pattern: String, ignoreCase: Bool)) -> Bool
=~ (strings: String[], pattern: String) -> Bool
=~ (strings: String[], options: (pattern: String, ignoreCase: Bool)) -> Bool
|~ |~ (string: String, pattern: String) -> Bool
|~ (string: String, options: (pattern: String, ignoreCase: Bool)) -> Bool

Range

Examples in the Wiki

Instance Methods

Name Signatures
times times (call: (T) -> ())
times (call: () -> ())
each each (call: (T) -> ())

Class Methods

Name Signature
random random (from: Int, to: Int) -> Range<Int>

Operators

Name Signature Function
= == <U: ForwardIndex> (first: Range<U>, second: Range<U>) -> Bool Compares 2 ranges

Dictionary

Examples in the Wiki

Instance Methods

Name Signatures
difference difference <V: Equatable> (dictionaries: Dictionary<KeyType, V>...) -> Dictionary<KeyType, V>
union union (dictionaries: Dictionary<KeyType, ValueType>...) -> Dictionary<KeyType, ValueType>
intersection intersection <K, V where K: Equatable, V: Equatable> (dictionaries: Dictionary<K, V>...) -> Dictionary<K, V>
has has (key: KeyType) -> Bool
isEmpty isEmpty () -> Bool
map map <K, V> (mapFunction map: (KeyType, ValueType) -> (K, V)) -> Dictionary<K, V>
mapValues mapValues <V> (mapFunction map: (KeyType, ValueType) -> (V)) -> Dictionary<KeyType, V>
each each(eachFunction each: (KeyType, ValueType) -> ())
filter filter(testFunction test: (KeyType, ValueType) -> Bool) -> Dictionary<KeyType, ValueType>
merge merge (dictionaries: Dictionary<KeyType, ValueType>...) -> Dictionary<KeyType, ValueType>
shift shift () -> (KeyType, ValueType)
groupBy groupBy <T> (groupingFunction group: (KeyType, ValueType) -> (T)) -> Dictionary<T, Array<ValueType>>
countBy countBy <T> (groupingFunction group: (KeyType, ValueType) -> (T)) -> Dictionary<T, Int>
any any (test: (KeyType, ValueType) -> (Bool)) -> Bool
all all (test: (KeyType, ValueType) -> (Bool)) -> Bool
reduce reduce <U> (initial: U, combine: (U, Element) -> U) -> U
pick, at pick (keys: KeyType[]) -> Dictionary
pick (keys: KeyType...) -> Dictionary
at (keys: KeyType...) -> Dictionary

Operators

Name Signature Function
- - <K, V: Equatable> (first: Dictionary<K, V>, second: Dictionary<K, V>) -> Dictionary<K, V> Difference
& & <K, V: Equatable> (first: Dictionary<K, V>, second: Dictionary<K, V>) -> Dictionary<K, V> Intersection
| | <K, V: Equatable> (first: Dictionary<K, V>, second: Dictionary<K, V>) -> Dictionary<K, V> Union

NSArray

Examples in the Wiki

Instance Methods

Name Signatures
cast cast <OutType> () -> OutType[]
flatten flatten <OutType> () -> OutType[]

Utilities

Examples in the Wiki

Class Methods

Name Signatures
after after <P, T> (n: Int, function: P -> T) -> (P -> T?)
func after <T> (n: Int, function: () -> T) -> (() -> T?)
once once <P, T> (function: P -> T) -> (P -> T?)
once <T> (call: Void -> T) -> (Void -> T?)
partial partial <P, T> (function: (P...) -> T, _ parameters: P...) -> ((P...) -> T?)
bind bind <P, T> (function: (P...) -> T, _ parameters: P...) -> (() -> T)
cached cached <P, R> (function: (P...) -> R) -> ((P...) -> R)
cached <P, R> (function: (P...) -> R, hash: ((P...) -> P)) -> ((P...) -> R)

To Do

  • Wiki
  • Xcode project for both iOS & OS X
  • Review code comments
  • Example project
  • Installation instructions
  • Benchmark
  • ...

About

A set of Swift extensions for standard types and classes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 98.7%
  • Other 1.3%