How to use an enum for iOS color assets + unit testing

Опубликовано: 14 Апрель 2021
на канале: Sparkcode
231
7

In this video I build off of the previous video about using color assets to have colors in the app support light and dark modes. Since color assets are not checked at compile time there is a chance that a color fails to load. It can be easy to accidentally misspell a color name or even delete a color asset by mistake and the compiler will be unaware. This can lead to crashes and bugs in our UI.

By using an enum we can represent all of our colors with cases. The real benefit to doing this is that we can make the enum CaseIterable which will generate an array of all our cases and allow us to write a simple unit test that loops over each color in the array. By doing this we will have a simple unit test that covers all our colors and requires no maintenance over time.

Previous video:    • How To Support iOS Dark Mode Colors (...