Codable synthesis for enums with associated values Swift 4 introduced support for automatically synthesizing conformance to the Encodable and Decodable protocols. It's a useful feature, most likely used by any application which handles JSON-based network requests. This Swift evolution pitch from Dario Rexin proposes extending auto-synthesis of these conformances to enums with associated values. I'm sure we will see this in an upcoming Swift version. Posted on December 8, 2020 #evolution #enum #codable
3 lesser-known ways of using Swift enums An enumeration defines a common type for a group of related values. Enumerations in Swift are first-class types, and they adopt many features traditionally only available by class types. In this post, Sarun Wongpatcharapakorn introduces us to some enum use cases in Swift that we might not be aware of. Posted on September 23, 2020 #enum
Switching with Associated Values In this post the objc.io, we learn how to use a computed property to reduce the complexity of switching on enums with associated values. Nice tip! Posted on September 10, 2018 #enum #associated
Enum iterations in Swift 4.2 John Sundell looks at CaseIterable, a protocol introduced in Swift 4.2. John describes what CaseIterable means, and demonstrates how we can use it to reduce boilerplate code. Posted on August 31, 2018 #swift 4.2 #enum
Polymorphic methods in enums This is an interesting discussion on the official Swift forums. It was started by Pablo Bendersky who would like to be able to add extensions on enums constrained by the enum case. I can see the value in this. Posted on August 13, 2018 #polymorphic #enum
Enumerating enum cases in Swift New in Swift 4.2 is the ability to specify that the compiler should generate a collection of an enum’s cases. In this post, Ole Begemann first shows us how we can use the new CaseIterable protocol with enums, before looking at how we can make other types CaseIterable. Posted on June 17, 2018 #swift 4.2 #enum
SE-0155 Status Update The Swift evolution proposal to Normalize Enum Case Representation is partly implemented, and this Swift Forums post lists the status for each goal of the proposal. This is a worthwhile proposal, with some nice improvements to the language, so it’s great to see progress being made. Posted on June 8, 2018 #evolution #enum
Enums And Optionals In this post, Soroush Khanlou explains how adding an extra case to an enum can replace the usage of optional enum values. As Soroush says, simplicity is king, and I agree that it’s worth taking the time to think about whether an extra optional case makes sense. Posted on April 16, 2018 #enum #optional
Swift Tip: Codable Enums In this post from Objc.io, we learn how to add Codable conformance to enums which have associated types. A very useful tip. Posted on January 29, 2018 #enum #codable
When Not to Use an Enum Matt Diephouse shows us when not to use an enum. Matt looks at a recent post from John Sundell, in which John used enums to build an app analytics API. Matt argues that structs would be better suited to build such an API, and explains why. Posted on December 10, 2017 #enum #struct