O'Reilly logo

Swift 3 ObjectOriented Programming - Second Edition by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Declaring a class that works with a constrained generic type

The following lines declare a PartyError enum that conforms to the ErrorType protocol. This way, we will be able to throw a specific exception in the next class that we will create. The code file for the sample is included in the swift_3_oop_chapter_06_03 folder:

    public enum PartyError: Error { 
      case insufficientMembersToRemoveLeader 
      case insufficientMembersToVoteLeader 
    } 

Tip

In case you worked with previous Swift versions, take into account that Swift 3 renamed ErrorType to Error. Swift 3 uses lowerCamelCase for enumeration values.

The following lines declare a Party class that takes advantage of generics to work with many types. The class name is followed by a less than sign (<), an ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required