Fresh Swift
  • About
  • Tags
Fresh Swift

#Optional


Reimplementation of Implicitly Unwrapped Optionals

This post on the official Swift blog details a new implementation of implicitly unwrapped optional which is available in the latest Swift snapshot. As always, it’s great to see changes like these - changes which eliminate inconsistencies and introduce clarity - being prioritized as the language evolves.

Posted on May 8, 2018

#optional 

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 

Optionals as Collections

Joshua Emmons returns to a post he wrote on dealing with optionals and failable initializers. Joshua goes back to basics, looking at how flapMap applies to optionals, and comes to realise that when we think of optionals as collections, things make more sense.

Posted on April 8, 2018

#optional  #flatmap 

Optional Forward Application

This is an interesting post from Joshua Emmons in which he looks at handling optional parameters when using failable initialisers. Joshua initially described an approach using a custom free function, before amending the post to recommend using the flatMap function available in the Swift standard library.

Posted on April 1, 2018

#optional  #flatmap 

Swift Evolution - Introducing `Unwrappable`, a biased unwrapping protocol

I really like this Swift evolution proposal from Erica Sadun and Chris Lattner. They propose an Unwrappable protocol, which introduces Optional-like behavior for any biased wrapped type. The major benefit here is that this would extend Optional syntactic sugar to any associated-type enumeration.

Posted on March 26, 2018

#evolution  #optional 

Useful Optional Extensions

Benedikt Terhechte has done the hard work and sifted through Github repositories and the documentation of other languages to bring us an exhaustive collection of useful Optional extensions. There are some really nice ones included here.

Posted on February 5, 2018

#optional 

Swift Non-Nil Values In An Array Of Optionals

Good tip from Use Your Loaf on how to work with an array of Optional values. Rather than use flatMap to iterate over the non-nil values, we can use pattern matching.

Posted on January 14, 2018

#optional  #patternmatching 

Total programming in Swift

André Videla describes what a total program is, and examines Swift in this context. André shows us how Swift uses its type system to encourage totality - code that won’t crash or get stuck in an infinite loop.

Posted on December 7, 2017

#totality  #optional  #error 

The Strange Case Of Mapping Over Optionals

Greg Heo with a post looking at how map and flatMap work when applied to optionals. Greg first looks at how traditional map and flatMap work when applied to collections, before taking a look at optionals. He provides code snippets of their Optional implementations, and offers guidance on when to use map and flatMap based on our requirements.

Posted on September 20, 2017

#optional  #map 

Making the case for Implicitly Unwrapped Optionals!

Alex Manarpies makes the case for using implicitly unwrapped optionals. He looks at the common practice of declaring IBOutlets as implicitly unwrapped optionals, and describes why he thinks this is the right approach.

Posted on September 13, 2017

#optional 
  • Older Posts →

 •  2019  •  Fresh Swift

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