From a19efad7fc938c2e505582a3541a3c083d0f85c8 Mon Sep 17 00:00:00 2001 From: Kyle Rokita Date: Fri, 11 Nov 2016 16:12:13 -0800 Subject: Added nil-coalescing operator --- swift.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/swift.html.markdown b/swift.html.markdown index b6554dc6..c17510b6 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -104,6 +104,11 @@ if let someOptionalStringConstant = someOptionalString { } } +// The nil-coalescing operator ?? unwraps an optional if it contains a non-nil value, or returns a default value. +var someOptionalString: String? +let someString = someOptionalString ?? "abc" +print(someString) // abc + // Swift has support for storing a value of any type. // For that purposes there is two keywords: `Any` and `AnyObject` // `AnyObject` == `id` from Objective-C -- cgit v1.2.3