Declaring a class that works with two constrained generic types

Now, it is time to code another protocol that will be used as a constraint later, when we define another class that takes advantage of generics with two constrained generic types. The following lines show the code for the DeeJayProtocol protocol. The public modifier followed by the protocol keyword and the protocol name, DeeJayProtocol, composes the protocol declaration, as follows. The code file for the sample is included in the swift_3_oop_chapter_06_10 folder:

    public protocol DeeJayProtocol { 
      var name: String { get } 
     
      init(name: String) 
     
      func playMusicToDance() 
      func playMusicToSing() 
    } 

The protocol declares a name: String read-only stored property and two method requirements:

Get Swift 3 ObjectOriented Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.