[Swift] function 1-2
iOS 2015. 7. 23. 23:45func sum(a:Int, b:Int)->Int{
return a+b
}
// inside of tuple
func sumAndCeiling(a:Int, b:Int)->(Int, Int){
var ceiling = a > b ? a: b
var sum = a + b
return (sum, ceiling)
}
var total = sum(14, 52)
total
var totalTuple = sumAndCeiling(14, 52)
totalTuple.0
totalTuple.1
func sumAndFloor(a:Int, b:Int)->(sum:Int, floor:Int){
var floor = a < b ? a : b
var sum = a + b
return (sum, floor)
}
var floorTuple = sumAndFloor(13, 4)
floorTuple.sum
floorTuple.floor
// arg-> return
func double(number:Int)->Int{
return number * 2
}
func triple(number:Int)->Int{
return number * 3
}
func modifyInt(#number:Int, #modifier:Int->Int)->Int{
return modifier(number);
}
modifyInt(number: 15, modifier: double)
modifyInt(number: 15, modifier: triple)
func buildIncrementor() -> () -> Int {
var count = 0
func incrementor() -> Int {
++count
return count
}
return incrementor
}
var incrementor = buildIncrementor()
incrementor()
incrementor()
incrementor()
'iOS' 카테고리의 다른 글
[Swift] function 1-4 (0) | 2015.07.23 |
---|---|
[Swift] function 1-3 (0) | 2015.07.23 |
[Swift] function 1-1 (0) | 2015.07.23 |
Loops, Switch Statements, and Ranges in Swift (0) | 2015.07.23 |
[swift] card (0) | 2015.07.23 |