diff options
author | Kyle Rokita <kyle.rokita@gmail.com> | 2016-11-11 16:12:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-11 16:12:13 -0800 |
commit | a19efad7fc938c2e505582a3541a3c083d0f85c8 (patch) | |
tree | 956ae5cd80ae6b004e0df614e4b796aa8302139c /swift.html.markdown | |
parent | d70ad72219c11cc085026c501362be6daa3154f0 (diff) |
Added nil-coalescing operator
Diffstat (limited to 'swift.html.markdown')
-rw-r--r-- | swift.html.markdown | 5 |
1 files changed, 5 insertions, 0 deletions
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 |