Thursday, March 10, 2016

Enums

Declaring

enum Direction {
    case Right
    case Left
}
// Or
enum Direction {
    case Right, Left
}
// Or
enum Direction: String {
    case Right = "Right turn only"
    case Left = "Left turn only"
}

Using

var turn = Direction.Right

if (turn == Direction.Right) {
    print("Turn \(turn)") // "Turn Right"
}

turn = .Left // Shorthand assignment

print("Turn \(turn)") // "Turn Left"

switch turn {
case .Right:
    print("You will be turning right.")
case .Left:
    print("You will be turning left.")
}
There is more to Enums than just this but to be honest, I will probably never use an Enum beyond this.

(Swift 2.2)

SwiftUI Search & Filter with Combine - Part 3 (iOS, Xcode 13, SwiftUI, 2...

In part 3 of the Searchable video series, I show you how to use Combine in #SwiftUI for the search and filter logic connected to the searcha...