Episode #462

Working with Measurements in Swift

30 minutes
Published on September 24, 2020

This video is only available to subscribers. Get access to this video and 571 others.

Foundation has a wonderfully useful support for dealing with measurements like distances, durations, temperatures and more in Swift. The Measurement class combines with a Unit type to constrain the measurements into their own domains. With this you can get functionality like conversion and addition. With MeasurementFormatter we can format these values for display in our UI based on the user's locale. In this episode we will explore how to use this API, how to extend the existing dimensions to add new measurement values, and how to create your own domain of measurements. For this we will model Throughput of Items in the game Factorio.

This episode uses Swift 5.3, Xcode 12.0.