Day 2 – 100 Days of Swift


Wow! I’ve been using swift for a bunch of years, and have never come across enum associations. Imaging getting to that on day two of a course.

import UIKit

enum Activity {
    case bored
    case running(destination: String)
    case talking(topic: String)
    case singing(volume: Int)
}

let talking = Activity.talking(topic: "football")

What you see above is the association added to the running, talking and singing values of the enum Activity. This way you can “associate” additional information to a specific enum, making it much more meaningful. Very cool.