iOS/π Swift
Side Effect - General
woozzang
2020. 11. 24. 10:05
κ°μ΄λ μνμ λ³κ²½μ΄ μΌμ΄λ¨μ μλ―Έ
λ Όλ¦¬μμμ side effectκ° λ°μν μ μλ μ½λλ₯Ό μ΄ν΄λ³΄κ² μ΅λλ€.
var a: Int = 1
var b: Int = 2
func addA (val: Int a){
a += 1
return true
}
func addB (val: Int b){
b += 1
return true
}
// short circuit μΌλ‘ addB()κ° νΈμΆλμ§ μλλ€
if addA() || addB() {
print(a) // 2
print(b) // 1
}
λ°λΌμ μλνμ§ μμ λ Όλ¦¬μ μ€λ₯κ° λ°μν μ μμΌλ―λ‘
κΌ νμν κ²½μ°κ° μλλΌλ©΄ 쑰건μμμ ν¨μλ₯Ό νΈμΆνλ μ½λλ μ§μν΄μΌ ν©λλ€.
λ.
μ΄μ κΈ: Nested Functions - Functions
Nested Functions - Functions
"ν¨μ λΈλ‘ λ΄λΆμ μ μλ ν¨μ" Example Code func outer() -> () -> () { print("outer") // "outer" var a: Int = 3 func inner(){ print("inner") // "inner" print(a) // 3 -> Nested Functionμ Scope : out..
woozzang.tistory.com