-
Book Overview & Buying
-
Table Of Contents
Mastering Swift 6 - Seventh Edition
By :
We can apply access controls to enumerations which will restrict or expose their visibility based on our design requirements. When we set an access level for an enumeration, all of its cases automatically inherit that access level. This ensures that the enumeration and its cases are consistently controlled. As with other entities the default access control for enumerations that are not explicitly marked, is internal. The following code same shows how we would use access controls with enumerations.
public enum Direction {
case north
case south
case east
case west
}
In this example we declare that the access level for the Direction enumeration is public. Raw values or associated values that may be of a customer type, in an enumeration definition must have an access level at least as high as the enumeration’s access level. As an example, we can’t use a type that has an access level of private as the raw-value type of an enumeration with an...