mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Added nil-coalescing operator
This commit is contained in:
parent
d70ad72219
commit
a19efad7fc
@ -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.
|
// Swift has support for storing a value of any type.
|
||||||
// For that purposes there is two keywords: `Any` and `AnyObject`
|
// For that purposes there is two keywords: `Any` and `AnyObject`
|
||||||
// `AnyObject` == `id` from Objective-C
|
// `AnyObject` == `id` from Objective-C
|
||||||
|
Loading…
Reference in New Issue
Block a user