-
swift - Protocols #7 (Protocol Composition)swift 2021. 1. 12. 19:09
protocol Resettable { func reset() } protocol Printable { func printValue() } class Size: Resettable, Printable { var width = 0.0 var height = 0.0 func reset() { width = 0.0 height = 0.0 } func printValue() { print(width, height) } } class Circle: Resettable { var radius = 0.0 func reset() { radius = 0.0 } } class Oval: Circle { } let r: Resettable = Size() let p: Printable = Size() var rp: Resettable & Printable = Size() var cr: Circle & Resettable = Circle() cr = Oval()
'swift' 카테고리의 다른 글
swift - Protocols #9 (Protocol Extension) (0) 2021.01.12 swift - Protocols #8 (Optional Protocol Requiredments) (0) 2021.01.12 swift - Protocols #6 (Protocol Types, protocol Conformance, Collection of protocol Types) (0) 2021.01.12 swift - Protocols #5 (Subscript Requiredments) (0) 2021.01.12 swift - Protocols #4 (Initializer Requiredments) (0) 2021.01.12