Home

Awesome

ExSwift

CocoaPods Carthage compatible Build Status

Set of Swift extensions for standard types and classes.

Installation

Because of Xcode errors it's not possible to integrate this project with Cocoapods or as Embedded Framework. Read more at Dev Forum

Use submodule and copy source code

  1. Add ExSwift as a submodule
  2. Open the ExSwift project folder, and drag ExSwift sub folder with source code into the file navigator of your Xcode project. Make sure you select add to target
  3. Use it
components.takeFirst() { $0.completed }

Contents

Extensions

Array

Examples in the Wiki

Instance Methods

NameSignature
firstfirst () -> Element?
lastlast () -> Element?
getget (index: Int) -> Element?
removeremove <U: Equatable> (element: U)
atat (indexes: Int...) -> Array
taketake (n: Int) -> Array
takeWhiletakeWhile (condition: (Element) -> Bool) -> Array
takeFirsttakeFirst (condition: (Element) -> Bool) -> Element?
tailtail (n: Int) -> Array
skipskip (n: Int) -> Array
skipWhileskipWhile (condition: (Element) -> Bool) -> Array
containscontains <T: Equatable> (item: T...) -> Bool
differencedifference <T: Equatable> (values: [T]...) -> [T]
intersectionintersection <U: Equatable> (values: [U]...) -> Array
unionunion <U: Equatable> (values: [U]...) -> Array
uniqueunique <T: Equatable> () -> [T]
indexOfindexOf <T: Equatable> (item: T) -> Int?
indexOfindexOf (condition: Element -> Bool) -> Int?
lastIndexOflastIndexOf <T: Equatable> (item: T) -> Int?
zipzip (arrays: Array<Any>...) -> [[Any?]]
partitionpartition (var n: Int, var step: Int? = nil) -> [Array]<br>partition (var n: Int, var step: Int? = nil, pad: Element[]?) -> [Array]
partitionAllpartitionAll (var n: Int, var step: Int? = nil) -> [Array]
partitionBypartitionBy <T: Equatable> (cond: (Element) -> T) -> [Array]
shuffleshuffle ()
shuffledshuffled () -> Array
sample (random)sample (size n: Int = 1) -> [T]
maxmax <T: Comparable> () -> T
minmin <T: Comparable> () -> T
eacheach (call: (Element) -> ())<br>each (call: (Int, Element) -> ())
eachRighteachRight (call: (Element) -> ())<br>eachRight (call: (Int, Element) -> ())
anyany (call: (Element) -> Bool) -> Bool
allall (call: (Element) -> Bool) -> Bool
rejectreject (exclude: (Element -> Bool)) -> Array
poppop() -> Element
pushpush(newElement: Element)
shiftshift() -> Element
unshiftunshift(newElement: Element)
insertinsert (newArray: Array, atIndex: Int)
groupBygroupBy <U> (groupingFunction group: (Element) -> (U)) -> [U: Array]
countBycountBy <U> (groupingFunction group: (Element) -> (U)) -> [U: Int]
countWherecountWhere (test: (Element) -> Bool) -> Int
reducereduce (combine: (Element, Element) -> Element) -> Element?
reduceRightreduceRight <U>(initial: U, combine: (U, Element) -> U) -> U
mapFiltermapFilter <V> (mapFunction map: (Element) -> (V)?) -> [V]
implodeimplode <C: ExtensibleCollection> (separator: C) -> C?
flattenflatten <OutType> () -> [OutType]
flattenAnyflattenAny () -> [AnyObject]
toDictionarytoDictionary <U> (keySelector:(Element) -> U) -> [U: Element]
toDictionarytoDictionary <K, V> (transform: (Element) -> (key: K, value: V)?) -> [K: V]
cyclecycle (n: Int? = nil, block: (T) -> ())
bSearchbSearch (block: (T) -> (Bool)) -> T?
bSearchbSearch (block: (T) -> (Int)) -> T?
sortUsingsortUsing<U:Comparable>(block: ((T) -> U)) -> [T]
transpositiontransposition (array: [[T]]) -> [[T]]
permutationpermutation (length: Int) -> [[T]]
repeatedPermutationrepeatedPermutation(length: Int) -> [[T]]
combinationcombination (length: Int) -> [[Element]]
repeatedCombination repeatedCombination (length: Int) -> [[Element]]

Class Methods

NameSignatures
rangerange <U: ForwardIndex> (range: Range<U>) -> Array<U>

Operators

NameSignatureFunction
-- <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
<code>|</code><code>| <T: Equatable> (first: Array<T>, second: Array<T>) -> Array<T></code>Union
* Int* <ItemType> (array: ItemType[], n: Int) -> [ItemType]Returns a new array built by concatenating int copies of self
* String* (array: String[], separator: String) -> StringEquivalent to array.implode(String)
[rangeAsArray: x..y]<br>[rangeAsArray: x...y]subscript(#rangeAsArray: Range<Int>) -> ArrayReturns the sub-array from index x to index y
[x, y, ...]subscript(first: Int, second: Int, rest: Int...) -> ArrayReturns the items at x, y

Int

Examples in the Wiki

Properties

Name
NSTimeIntervalyears
NSTimeIntervalyear
NSTimeIntervaldays
NSTimeIntervalday
NSTimeIntervalhours
NSTimeIntervalhour
NSTimeIntervalminutes
NSTimeIntervalminute
NSTimeIntervalseconds
NSTimeIntervalsecond

Instance Methods

NameSignatures
timestimes <T> (call: (Int) -> T)<br>times <T> (call: () -> T)<br>times (call: () -> ())
isEvenisEven () -> Bool
isOddidOdd () -> Bool
upToupTo (limit: Int, call: (Int) -> ())
downTodownTo (limit: Int, call: (Int) -> ())
clampclamp (range: Range<Int>) -> Int<br>clamp (min: Int, max: Int) -> Int
isInisIn (range: Range<Int>, strict: Bool = false) -> Bool
digitsdigits () -> Array<Int>
absabs () -> Int
gcdgcd (n: Int) -> Int
lcmlcm (n: Int) -> Int

Class Methods

NameSignatures
randomrandom(min: Int = 0, max: Int) -> Int

Float

Examples in the Wiki

Instance Methods

NameSignature
absabs () -> Float
sqrtsqrt () -> Float
roundround () -> Float
ceilceil () -> Float
floorfloor () -> Float
clampclamp (min: Float, _ max: Float) -> Float

Class Methods

NameSignatures
randomrandom(min: Float = 0, max: Float) -> Float

String

Examples in the Wiki

Properties

Name
length
capitalized

Instance Methods

NameSignature
explodeexplode (separator: Character) -> [String]
atat (indexes: Int...) -> [String]
matchesmatches (pattern: String, ignoreCase: Bool = false) -> [NSTextCheckingResult]?
insertinsert (index: Int, _ string: String) -> String
ltrimmedltrimmed () -> String
ltrimmedltrimmed (set: NSCharacterSet) -> String
rtrimmedrtrimmed () -> String
rtrimmedrtrimmed (set: NSCharacterSet) -> String
trimmedtrimmed () -> String
rtrimmedrtrimmed (set: NSCharacterSet) -> String
toDoubletoDouble() -> Double?
toFloattoFloat() -> Float?
toUInttoUInt() -> UInt?
toBooltoBool() -> Bool?
toDatetoDate(format : String? = "yyyy-MM-dd") -> NSDate?
toDateTimetoDateTime(format : String? = "yyyy-MM-dd hh-mm-ss") -> NSDate?

Class Methods

NameSignature
randomfunc random (var length len: Int = 0, charset: String = "...") -> String

Operators

NameSignature
[x]subscript(index: Int) -> String?
[x..y]<br>[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<br>=~ (string: String, options: (pattern: String, ignoreCase: Bool)) -> Bool<br>=~ (strings: [String], pattern: String) -> Bool<br>=~ (strings: [String], options: (pattern: String, ignoreCase: Bool)) -> Bool
<code>|~</code><code>|~ (string: String, pattern: String) -> Bool</code><br><code>|~ (string: String, options: (pattern: String, ignoreCase: Bool)) -> Bool</code>

Range

Examples in the Wiki

Instance Methods

NameSignatures
timestimes (call: (T) -> ())<br>times (call: () -> ())
eacheach (call: (T) -> ())
toArraytoArray () -> [T]

Class Methods

NameSignature
randomrandom (from: Int, to: Int) -> Range<Int>

Operators

NameSignatureFunction
=== <U: ForwardIndex> (first: Range<U>, second: Range<U>) -> BoolCompares 2 ranges

Dictionary

Examples in the Wiki

Instance Methods

NameSignatures
differencedifference <V: Equatable> (dictionaries: [Key: V]...) -> [Key: V]
unionunion (dictionaries: [Key: Value]...) -> [Key: Value]
intersectionintersection <K, V where K: Equatable, V: Equatable> (dictionaries: [K: V]...) -> [K: V]
hashas (key: Key) -> Bool
mapmap <K, V> (mapFunction map: (Key, Value) -> (K, V)) -> [K: V]
mapFiltermapFilter <K, V> (mapFunction map: (Key, Value) -> (K, V)?) -> [K: V]
mapValuesmapValues <V> (mapFunction map: (Key, Value) -> (V)) -> [Key: V]
mapFilterValuesmapFilterValues <V> (mapFunction map: (Key, Value) -> V?) -> [Key: V]
eacheach(eachFunction each: (Key, Value) -> ())
filterfilter(testFunction test: (Key, Value) -> Bool) -> [Key: Value]
mergemerge (dictionaries: [Key: Value]...) -> [Key: Value]
shiftshift () -> (Key, Value)
groupBygroupBy <T> (groupingFunction group: (Key, Value) -> (T)) -> [T: Array<Value>]
countBycountBy <T> (groupingFunction group: (Key, Value) -> (T)) -> [T: Int]
countWherecountWhere (test: (Key, Value) -> (Bool)) -> Int
anyany (test: (Key, Value) -> (Bool)) -> Bool
allall (test: (Key, Value) -> (Bool)) -> Bool
reducereduce <U> (initial: U, combine: (U, Element) -> U) -> U
pick, atpick (keys: [Key]) -> Dictionary<br>pick (keys: Key...) -> Dictionary<br>at (keys: Key...) -> Dictionary
toArraytoArray <V> (mapFunction map: (Key, Value) -> V) -> [V]

Operators

NameSignatureFunction
-- <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
<code>|</code><code>| <K, V: Equatable> (first: Dictionary<K, V>, second: Dictionary<K, V>) -> Dictionary<K, V></code>Union

NSArray

Examples in the Wiki

Instance Methods

NameSignatures
castcast <OutType> () -> [OutType]
flattenflatten <OutType> () -> [OutType]
flattenAnyflattenAny () -> [AnyObject]

SequenceOf

The following operations can be performed on sequences and are evaluated lazily. Each operation only takes the data it requires from the source sequence in order to return its result.

The Sequence protocol cannot be extended, hence the following are extensions to SequenceOf. They can be used as follows:

var source: Sequence = ...
var filteredSequence = SequenceOf(source).filter { ... }

Instance Methods

NameSignatures
firstfirst () -> T?
anyany (call: (T) -> Bool) -> Bool
getget (index: Int) -> T?
getget (range: Range<Int>) -> SequenceOf<T>
indexOfindexOf <U: Equatable> (item: U) -> Int?
filterfilter(include: (T) -> Bool) -> SequenceOf<T>
rejectreject (exclude: (T -> Bool)) -> SequenceOf<T>
skipWhileskipWhile(condition:(T) -> Bool) -> SequenceOf<T>
skipskip (n:Int) -> SequenceOf<T>
containscontains<T:Equatable> (item: T) -> Bool
taketake (n:Int) -> SequenceOf<T>
takeWhiletakeWhile (condition:(T?) -> Bool) -> SequenceOf<T>

Double

Examples in the Wiki

Instance Methods

NameSignature
absabs () -> Double
sqrtsqrt () -> Double
roundround () -> Double
ceilceil () -> Double
floorfloor () -> Double
clampclamp (min: Double, _ max: Double) -> Double
roundToNearestroundToNearest(increment: Double) -> Double

Class Methods

NameSignatures
randomrandom(min: Double = 0, max: Double) -> Double

NSDate

Properties

NameSignatures
yearInt
monthInt
weekdayInt
weekMonthInt
daysInt
hoursInt
minutesInt
secondsInt

Instance Methods

NameSignatures
addadd(seconds:Int=0, minutes:Int = 0, hours:Int = 0, days:Int = 0, weeks:Int = 0, months:Int = 0, years:Int = 0) -> NSDate
addSecondsaddSeconds (seconds:Int) -> NSDate
addMinutesaddMinutes (minute:Int) -> NSDate
addHoursaddHours(hours:Int) -> NSDate
addDaysaddDays(days:Int) -> NSDate
addWeeksaddWeeks(weeks:Int) -> NSDate
addMonthsaddMonths(months:Int) -> NSDate
addYearsaddYears(years:Int) -> NSDate
isAfterisAfter(date: NSDate) -> Bool
isBeforeisBefore(date: NSDate) -> Bool
getComponentgetComponent (component : NSCalendarUnit) -> Int

Operators

NameSignatures
====(lhs: NSDate, rhs: NSDate) -> Bool
<<(lhs: NSDate, rhs: NSDate) -> Bool
>>(lhs: NSDate, rhs: NSDate) -> Bool
<=<=(lhs: NSDate, rhs: NSDate) -> Bool
>=>=(lhs: NSDate, rhs: NSDate) -> Bool
====(lhs: NSDate, rhs: NSDate) -> Bool

Utilities

Examples in the Wiki

Class Methods

NameSignatures
afterafter <P, T> (n: Int, function: P -> T) -> (P -> T?)<br>func after <T> (n: Int, function: () -> T) -> (() -> T?)
onceonce <P, T> (function: P -> T) -> (P -> T?)<br>once <T> (call: Void -> T) -> (Void -> T?)
partialpartial <P, T> (function: (P...) -> T, _ parameters: P...) -> ((P...) -> T?)
bindbind <P, T> (function: (P...) -> T, _ parameters: P...) -> (() -> T)
cachedcached <P, R> (function: P -> R) -> (P -> R)<br>cached <P, R> (function: (P...) -> R) -> ((P...) -> R)<br>cached <P, R> (function: (P...) -> R, hash: ((P...) -> P)) -> ((P...) -> R)

Operators

NameSignatures
<=><=> <T: Comparable>(lhs: T, rhs: T) -> Int

To Do