Introduction to iOS App Design Patterns

  • Enums turned out to be deeper than I thought.
  • Using associated values, you can cleanly create variables that are only necessary under certain conditions.

enum.swift

enum State {
	case inputting(validationError: Error?)
	case sending
	case sent(Message)
}
  • In this case, it is good to use this because we only want to hold the value of Message when it is in the “sent” state.