swift 함수 연습 2
[part1]
func helloGenerator(message : String) -> (String) -> String
{
func hello(name : String) -> String
{
return name + message
}
return hello
}
let hello2 = helloGenerator(message : "미소미소")
print(hello2("안녕 "))
결과 :
안녕 미소미소
/*
hello 의 반환 타입은 String 이고,
hello 는 "문자열을 받아서 문자열을 반환하는 함수"이다.
helloGenerator 의 반환 타입은 (String) -> String 이고,
helloGenerator 는 ""문자열을 받아서 문자열을 반환하는 함수"를 반환하는 함수"이다.
*/
https://devxoul.gitbooks.io/ios-with-swift-in-40-hours/content/Chapter-3/functions-and-closures.html
[part2]
func helloGenerator(message : String) -> (String, Int) -> String
{
func helloBoy(name : String, age : Int) -> String
{
//return "이름" + name + "나이" + String(age) + message
return "이름 : \(name) 나이 : \(age) + \(message)"
}
return helloBoy
}
let hello2 = helloGenerator(message : "냠냠")
print(hello2("미소",20))
결과 :
이름 : 미소 나이 : 20 + 냠냠