func getValue() -> Double {
return 3.31
}
getValue()
func getTuple(strName:String, withAge:Int) -> (name:String, age:Int){
return (strName, withAge)
}
getTuple("Jsson lee", withAge: 39).name
func myNewFunc(tuple:(name:String, age:Int)) -> String {
return tuple.name
}
myNewFunc(("nicegood", 13))
func funcWithoutReturn() {
print("this is non-returnable function")
}
funcWithoutReturn()
func funcWithDefaultParameter(inputName:String="JOHN DOE", age:Int) -> (killCount:Int, lastAccessPoint:String) {
return (age, "Kill House")
}
funcWithDefaultParameter("hello", age: 3)
var newDate = NSDate()
func getAveList(scores:Int..., total:Double) -> Double {
var total = 0
for p in scores{
total += p
}
return Double(total)/Double(scores.count)
}
func getAve(scores:[Int]) -> Double {
var total = 0
for p in scores{
total += p
}
return Double(total)/Double(scores.count)
}
getAve([0,0,0,1,2,3,4])
getAveList(1,2,3,4, total:3.1)
var value = 12
func testFun(var param:Int) -> Int {
param += 1
return param
}
print(testFun(value))
print(value)
var value2 = 12
func testFun2(inout param:Int) -> Int { // inout 지시자는 원형타입의 파라미터 주소값을 넘기는 형태로 함수 실행토록 해줌
param += 1
return param
}
print(testFun2(&value2))
print(value2)
댓글 없음:
댓글 쓰기