Swift 3: Protocol Part 3
As I alluded to details about the protocol in two-part ( Protocol Part1 and Protocol Part 2 ) previous posts. Now this my last post with some more information about the protocol. All code example tested on Xcode 8.1. Class-Only Protocols: we can stop the protocol adoption to class types by putting class keywords in the protocol inheritance list. This class always should be in first place in the protocols inheritance list, before if the type is going to inherit any other protocol. protocol ClassOnlyProtocol : class , myProtocol { } In this ClassOnlyProtocol can be adopted by class types only if any enum and structure try to write any definition which tries to adopt protocol will end up with a compile-time error. Protocol Composition With the help of protocol composition, we can create a single requirement that could combine multiple protocols. It can use a require a type to conform to multiple protocols at once. protocol FirstName { var firstName ...