Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Другое замечание относительно variadic параметров: variadic параметр должен быть последним параметром в вашем списке параметров!
func add (a1:Int, a2:Int) ->Int {return (a1 + a2)}
func multiply (a1:Int, a2:Int) ->Int {return (a1 * a2)}
func funcReturnFunc (funcOperation: (Int,Int) -> Int) -> (Int, Int) ->Int {
return funcOperation
}
func funcReturnFunc2 (funcOperation: (Int,Int) -> Int) -> (Int, Int) ->Int {
return funcReturnFunc(funcOperation)
}
let returnedFunction = funcReturnFunc2 (multiply)
let returnedFunction1 = funcReturnFunc2 (add)
returnedFunction(5,6) // Получим 30 на playground
returnedFunction1(5,6) // Получим 11 на playground
<source>
var test = function (i) {
return function (j) {
return function (k) {
// oh finally!
return i + j + k;
};
};
};
test(1)(2)(3); // == 6
func add (i:Int, j:Int, k:Int, l:Int) -> Int {return(i + j + k + l)}
// 1- ый метод
func curry<A,B,C,D,R>(f: (A,B,C,D) -> R) -> A -> B -> C -> D -> R {
return { a in { b in { c in { d in f(a,b,c,d) } } } }
}
let sum4 = curry (add )
// 2- ый метод (curried function in Swift)
func sum4Swift(i: Int)(j:Int)(k: Int)(l:Int) -> Int {
return add(i, j, k, l)
}
sum4 (1)(2)(3)(5) // playground 11
sum4Swift (1)(j: 2)(k: 3)(l: 5) // playground 11
func chained(i: Int) -> (Int) -> (Int) -> Int {
return { (j: Int) -> (Int) -> Int in
return { (k: Int) -> Int in
return i + j + k;
}
}
}
chained(1)(2)(3)
" alt=«image»/> override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { } //Swift
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {} // Objective-C
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {} //Swift
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {} //Objective-C
<source>
Многоликие функции Swift