-
[Swift] 타입으로서의 프로토콜 ( Protocol as Type )iOS/🟠 Swift 2021. 1. 19. 15:32
참고 자료: Protocols - swift.org 프로토콜은 First Class Citizen 이기 때문에, 하나의 독립적인 타입 ( a fully fledged types ) 으로 사용할 수 있습니다. 따라서 아래 3가지가 가능합니다. 1. function, method, initializer 의 parameter 와 return type으로 사용 가능 2. constant, variable, property 의 type 으로 사용 가능 3. array, dictionary 와 같은 컨테이너의 item의 type으로 사용 가능 그리고 타입이기 때문에 Upper Camel Case 를 사용합니다. (e.g. RandomNumberGenerator, FullyNamed ...) class Dice { ..
-
3 features of First Class Citizen - FunctioniOS/🟠 Swift 2020. 11. 2. 18:48
can be stored in variavles and data structures 상수나 변수에 저장할 수 있습니다. can be passed as a parameter to a function 매개변수로 함수에 전달 될 수 있습니다. can be returned as the result of a function 함수의 결과로 반환될 수 있습니다. 끝! 이전 글: Tuples - Tuples Tuples - Tuples " 하나의 상수 혹은 변수에 여러 개의 값을 저장할 수 있을까?" 기존의 Int, String 과 같은 타입은 하나의 상수 혹은 변수에 하나의 값을 저장할 수 있었습니다. 이런 타입을 Scalar Type 이라고 합니다 woozzang.tistory.com