mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
Explain Optional Chaining
Without going into too much detail, mention optional chaining so it's not confusing that there is a question mark suffix (it's not currently mentioned anywhere on the page).
This commit is contained in:
parent
6915f5bfd0
commit
7a55b4a9b1
@ -445,7 +445,10 @@ class MyShape: Rect {
|
||||
|
||||
func grow() {
|
||||
sideLength += 2
|
||||
|
||||
|
||||
// Place a question mark after an optional property, method, or
|
||||
// subscript to gracefully ignore a nil value and return nil
|
||||
// instead of throwing a runtime error ("optional chaining").
|
||||
if let allow = self.delegate?.canReshape?() {
|
||||
// test for delegate then for method
|
||||
self.delegate?.reshaped?()
|
||||
|
Loading…
Reference in New Issue
Block a user