Fresh Swift
  • About
  • Tags
Fresh Swift

#enum


Why Dictionary sometimes encodes itself as an array

Oleb Begemann with a very interesting post on why Swift dictionaries sometimes encode themselves as arrays when using Swift 4’s Codable protocols. I wasn’t aware of this limitation, and as he points out, there is no clean and simple fix for it.

Posted on December 6, 2017

#codable  #enum 

Building an enum-based analytics system in Swift

John Sundell demonstrates an approach to adding app analytics based on enums. It’s a nice idea, allowing us to add analytic events to our code without being tied to any particular analytics provider.

Posted on December 5, 2017

#enum  #analytics 

Why Swift Enums with Associated Values Cannot Have a Raw Value

In this post Mischa Hildebrand explains why Swift enums with associated values cannot also have a raw value. Even though we may be familiar with this limitation, it’s interesting to think about the reasoning behind it.

Posted on November 27, 2017

#enum 

The power of switch statements in Swift

John Sundell looks at Swift switch statements, and demonstrates how versatile and powerful they can be, especially when combined with types defined using enums, tuples, and sets.

Posted on October 8, 2017

#switch  #enum  #set 

Codable Enums

Swift 4’s Codable protocols make it very easy to encode and decode conforming types, even working with enums when the enums rawValue also conforms to Codable. However, things get a little bit more complicated when dealing with enums which have associated values. This post from Little Bites of Cocoa shows us how we can handle such a situation.

Posted on October 7, 2017

#codable  #swift 4  #enum 

Swift evolution - Non-Exhaustive Enums

I really like this Swift evolution proposal from Jordan Rose. It aims to distinguish between enums which are exhaustive (they will never get new cases), and enums which are non-exhaustive, and to ensure that clients handle any future cases when dealing with the latter.

Posted on September 26, 2017

#evolution  #enum 

Listing all cases in an Swift enum

Swift enumerations allows us to define a common type for a group of related values, and are a great way to keep our code organized and type-safe. However, one feature missing is the ability to easily list all available cases for an enum. In this post, Bartosz Polaczyk shows us how we can define our enums in such a way that that this is possible. Very useful.

Posted on September 18, 2017

#enum 

Modelling state in Swift

Dealing with state is hard, error prone, and unavoidable. In this post, John Sundell looks at some of the commonly used techniques we can apply when dealing with state in Swift. I think the first two points - having a single source of truth, and making states exclusive - are key.

Posted on July 12, 2017

#state  #enum 

Mixing Constant and Literal Strings

Joshua Emmons shows us how to avoid implementing a stringly-typed interface. Using an enum with an associated type, we can enforce the use of constants, while also allowing for unexpected and unknowable string values.

Posted on June 2, 2017

#string  #enum 

Swift enums are sum types, and that makes them very interesting

Mislav Javor with an explanation of the Algebraic product and sum types in terms of Swift struct and enum types. He demonstrates that enums being sum types makes them particularly interesting. Simple examples mean no PhD in mathematics is required!

Posted on April 23, 2017

#enum 
  • ← Newer Posts
  • Older Posts →

 •  2021  •  Fresh Swift

Hugo v0.80.0 powered  •  Theme by Beautiful Jekyll adapted to Beautiful Hugo