Skip to content

5sw.de

  • Blog
  • About Me
  • Apps
  • Mastodon
  • GitHub
  • Stack Overflow

Tag Archives: enum

Handling unknown enum cases

Even though they are sometimes overused, enums are still a great tool. Thanks to Codable they can easily be decoded from JSON sent by your backend. This is great until you need to add a new case to the enum. Then you have to either deal with versioning your API or you need to tell …

Continue reading “Handling unknown enum cases”

Posted bySvenJanuary 29, 2022January 29, 2022Posted inSwiftTags: Codable, enum, JSON, Swift

Enum or struct?

I often see a pattern where there is an enum with a bunch of computed properties that return a different value for each case. In the rest of the code base then only those properties are used. Something like this: This works, but quite often can be improved by using a struct instead of an …

Continue reading “Enum or struct?”

Posted bySvenJanuary 23, 2022Posted inSwiftTags: enum, Swift
5sw.de, Proudly powered by WordPress.