Andy Kayley
iOS Engineer, Gamer, Family Man
Swift's Nil Coalescing Operator AKA the '?? Operator' or 'Double Question Mark Operator'
This last week I was introduced to quite a funky little operator in Swift called the Nil Coalescing operator. It is basically a shorthand for the ternary conditional operator when used to test for nil.
For example traditionally in many programming languages you could do something like this to check for nil/null…
Here if the condition is not nil the value of stringVar will be returned otherwise the value “a default string” is returned.
This can be shortened in Swift by using the Nil Coalescing operator.
This does exactly the same thing, if stringVar is not nil then it is returned, however if it is nil the value “a default string” is returned.
Love it.
February 2016
October 2015
March 2013
September 2011
June 2010
May 2009
February 2009
July 2008
- How to Print Out Bind Variables in Java Prepared Statements..
- How to get Logitech QuickCam Ultra Vision working in Ubuntu.