iOS/๐ Swift
Nested Functions - Functions
woozzang
2020. 11. 8. 19:10
"ํจ์ ๋ธ๋ก ๋ด๋ถ์ ์ ์๋ ํจ์"
Example Code
func outer() -> () -> () {
print("outer") // "outer"
var a: Int = 3
func inner(){
print("inner") // "inner"
print(a) // 3 -> Nested Function์ Scope : outer local block
}
return inner
}
let f = outer()
f()
outer ๋ธ๋ก ์ธ๋ถ์์ inner ์ ์ ๊ทผ ํ๋ ๋ฐฉ๋ฒ
- ์ ์ฝ๋์ ๊ฐ์ด inner๋ฅผ ๋ฆฌํดํจ์ผ๋ก์ ๊ฐ์ ์ Scope ํ์ฅ์ ํตํด inner์ ์ ๊ทผํ ์ ์์ต๋๋ค.
๋.
์ด์ ๊ธ: Function Types - Functions
Function Types - Functions
Function Types๋ ๋ณ์๋ ์์์ ํจ์๋ฅผ assign ํ๋ ๊ฒฝ์ฐ, ํ์ ์ ๋ช ์ํ ๋ ํ์ํฉ๋๋ค. Swift์์ ํจ์๋ first-class citizen ์ด๋ฏ๋ก, ๋ณ์๋ ์์์ ํจ์๋ฅผ assign ํ ์ ์์ต๋๋ค. ์ด์ ๊ธ์์ Function No..
woozzang.tistory.com