Swift - Day 4 : Resting and Enums
Today was a reminder of the importance of taking time to rest. Not having enough sleep finally caught up with me and impeded my productivity during the day. So I’m going to catchup on some sleep but before I do, here’s what I’ve learned about swift’s enums.
Enumerations in Swift define a common type for a group of related values. Unlike other languages enumerations in Swift don’t have to provide a value for each case. The case keyword is used to define new enumeration cases.
An enumeration name has to start with a capital letter as shown above. The type of enum is inferred on initialisation and can be passed a shorter syntax
.forward once declared.
It is sometimes valuable to store variables or types within this enums to use later. This is what associated values are used for.
One of the things I like about swift enumerations is how they are matched. Suppose we have a function that has an Enum as a parameter.
When the function is called and the argument is passed we simply pass it as
.forward instead of having to pass it as