Opaque Types1 [Swift] Opaque Type(불투명 타입) - 2 Boxed Protocol Types 박스드 프로토콜 타입은 “there exists a type T such that T conforms to the protocol” 라는 구절에서 따와 실존적 타입(existential type)이라고도 한다. 박스드 프로토콜 타입을 만들기 위해, 프로토콜 이름 앞에 any를 작성한다. 다음은 예시이다: struct VerticalShapes: Shape { var shapes: [any Shape] func draw() -> String { return shapes.map { $0.draw() }.joined(separator: "\n\n") } } let largeTriangle = Triangle(size: 5) let largeSquare = Square(si.. 2023. 8. 13. 이전 1 다음