클로저2 클로저 - 캡쳐 캡쳐: 클로저가 자신이 정의된 환경에서 변수나 상수를 기억하고, 나중에 사용할 수 있도록 하는 방법 클로저가 만들어진 시점의 주변 환경을 기억하고 사용할 수 있게 함 func makeIncrementer(step: Int) -> () -> Int { var total = 0 let incrementer: () -> Int = { total += step return total } return incrementer } let incrementByTwo = makeIncrementer(step: 2) let first = incrementByTwo() // first = 2 let second = incrementByTwo() // second = 4 makeIncrementer(step: int)는 ste.. 2023. 10. 17. 클로저 (Closures) 1. 클로저 일급 객체로서, 함수처럼 기능을 수행하는 블록. named closure(func 키워드를 사용하는 일반적인 함수), unnamed closure(익명함수) 두 가지 종류가 있음 다음과 같은 구조를 가진다. { (파라미터) -> 반환타입 in // 실행 코드 } let multiply: (Int, Int) -> Int = { (a, b) in return a * b } 2. 클로저의 축약 https://babbab2.tistory.com/82 Swift) 클로저(Closure) 정복하기(2/3) - 문법 경량화 / @escaping / @autoclosure 안녕하세요 :) 소들입니다 이번 포스팅인 저번 포스팅에 이어 클로저에 대해 다뤄보려고 해요!!! 저번 포스팅이 클로저의 표현식과 특징?.. 2023. 10. 17. 이전 1 다음