Swift. 클로저(Closures)
정의 클로저는 일정 기능을 하는 코드를 하나의 블록으로 모아놓은 것이다. - 클로저는 상수 안에 들어 있지 않아도 블럭 그대로 존재할 수 있는 코드의 블럭이다. - 클로저는 변수나 상수가 선언된 위치에서 참조(reference)를 capture하고 저장이 가능한데, 이를 변수나 상수의 클로징(잠금)이라고 부른다. 이 클로징 때문에 클로저가 클로저로 불리게 된다. - Cf. 함수는 이름이 있는 클로저이다. 함수는 클로저에 포함된 개념이므로 모든 함수는 클로저이다. 함수는 일급시민인데, 그렇기 때문에 함수를 타입으로 지정하거나, 인자값으로 넘기거나, 리턴값으로 받을 수 있는 등 함수 자체를 값으로 취급할 수 있다. 클로저도 일급시민*이기 때문에 파라미터, 변수, 상수 등으로 저장과 전달을 할 수 있다. 문법..
2019. 5. 7. 11:30