Bruno Bilescky
Aug 25, 2017 · 1 min read

Great article! But one thing that we can think of is that enums can have computed properties, so instead of storing self.cells = loaded.cells ( in the last enum example, inside the didSet), we can make a computed property in the State enum, and either return the loaded cells, or an empty array. This way you only keep the state in one place. In the example, what happens is that you didn't clear the self.cells in the other cases. Using computed properties you can still have a finite number of states, and a clear picture for each value in every state.

var cells: [Cells] {

guard case let .loaded(cells)= self else { return [] }

return cells

}

)

    Bruno Bilescky

    Written by

    iOS developer

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade