iOS-Swift-Developers/ExSwift

 
 

Repository files navigation

CocoaPodsCarthage compatibleBuild Status

Set of Swift extensions for standard types and classes.

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

  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 }

Examples in the Wiki

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]
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) -> ())
each (call: (Int, Element) -> ())
eachRighteachRight (call: (Element) -> ())
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]]
repeatedCombinationrepeatedCombination (length: Int) -> [[Element]]
NameSignatures
rangerange <U: ForwardIndex> (range: Range<U>) -> Array<U>
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
|| <T: Equatable> (first: Array, second: Array) -> ArrayUnion
* 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]
[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

Examples in the Wiki

Name
NSTimeIntervalyears
NSTimeIntervalyear
NSTimeIntervaldays
NSTimeIntervalday
NSTimeIntervalhours
NSTimeIntervalhour
NSTimeIntervalminutes
NSTimeIntervalminute
NSTimeIntervalseconds
NSTimeIntervalsecond
NameSignatures
timestimes <T> (call: (Int) -> T)
times <T> (call: () -> T)
times (call: () -> ())
isEvenisEven () -> Bool
isOddidOdd () -> Bool
upToupTo (limit: Int, call: (Int) -> ())
downTodownTo (limit: Int, call: (Int) -> ())
clampclamp (range: Range<Int>) -> Int
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
NameSignatures
randomrandom(min: Int = 0, max: Int) -> Int

Examples in the Wiki

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

Examples in the Wiki

Name
length
capitalized
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?
NameSignature
randomfunc random (var length len: Int = 0, charset: String = "...") -> String
NameSignature
[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

Examples in the Wiki

NameSignatures
timestimes (call: (T) -> ())
times (call: () -> ())
eacheach (call: (T) -> ())
toArraytoArray () -> [T]
NameSignature
randomrandom (from: Int, to: Int) -> Range<Int>
NameSignatureFunction
=== <U: ForwardIndex> (first: Range<U>, second: Range<U>) -> BoolCompares 2 ranges

Examples in the Wiki

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
pick (keys: Key...) -> Dictionary
at (keys: Key...) -> Dictionary
toArraytoArray <V> (mapFunction map: (Key, Value) -> V) -> [V]
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
|| <K, V: Equatable> (first: Dictionary<K, V>, second: Dictionary<K, V>) -> Dictionary<K, V>Union

Examples in the Wiki

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

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 { ... }
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>

Examples in the Wiki

NameSignature
absabs () -> Double
sqrtsqrt () -> Double
roundround () -> Double
ceilceil () -> Double
floorfloor () -> Double
clampclamp (min: Double, _ max: Double) -> Double
roundToNearestroundToNearest(increment: Double) -> Double
NameSignatures
randomrandom(min: Double = 0, max: Double) -> Double
NameSignatures
yearInt
monthInt
weekdayInt
weekMonthInt
daysInt
hoursInt
minutesInt
secondsInt
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
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

Examples in the Wiki

NameSignatures
afterafter <P, T> (n: Int, function: P -> T) -> (P -> T?)
func after <T> (n: Int, function: () -> T) -> (() -> T?)
onceonce <P, T> (function: P -> T) -> (P -> T?)
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)
cached <P, R> (function: (P...) -> R) -> ((P...) -> R)
cached <P, R> (function: (P...) -> R, hash: ((P...) -> P)) -> ((P...) -> R)
NameSignatures
<=><=> <T: Comparable>(lhs: T, rhs: T) -> Int
  • 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 99.3%
  • Other 0.7%