Do you need help on a specific subject? Use the contact form (Request a blog entry) on the right hand side.


The nil case in swift switch statements | Swift Short & Sweet

I am not really sure when this was added or even if this was possible from the beginning, but I just re-discovered a very sweet feature of the switch statement in Swift: The nil case.

enum OneTwo { case one, two }

var ot: OneTwo?

switch ot {
case nil: print("Nil")
case .one?: print("One")
case .two?: print("Two")

It even detects the absence of the nil case (when you forget) and asks for a default when you do so.

As near to perfect as it gets imo.

Happy coding...

Did this help?, then please help out a small independent.
If you decide that you want to make a small donation, you can do so by clicking this
link: a cup of coffee ($2) or use the popup on the right hand side for different amounts.
Payments will be processed by PayPal, receiver will be sales at balancingrock dot nl
Bitcoins will be gladly accepted at: 1GacSREBxPy1yskLMc9de2nofNv2SNdwqH

We don't get the world we wish for... we get the world we pay for.

No comments:

Post a Comment