File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -479,10 +479,12 @@ case let .qrCode(productCode):
479479 ```
480480-->
481481
482- When you're matching just one case of an enumeration,
483- you can use the shorter ` if case ` syntax
482+ When you're matching just one case of an enumeration ---
483+ for example,
484+ to extract its associated value ---
485+ there's a shorter syntax you can use
484486instead of writing a full switch statement.
485- For example :
487+ Here's what it looks like :
486488
487489``` swift
488490if case .qrCode (let productCode) = productBarcode {
@@ -494,8 +496,10 @@ In this code,
494496the condition for the ` if ` statement starts with ` case ` ,
495497indicating that the condition is a pattern instead of a Boolean value.
496498If the pattern matches,
497- the condition for the ` if ` is considered to be true;
498- otherwise it's false.
499+ the condition for the ` if ` is considered to be true,
500+ and the code in the body of the ` if ` statement runs.
501+ The patterns you can write after ` if case `
502+ are the same as the patterns you can write in a switch case.
499503Just like in the switch statement earlier,
500504the ` productBarcode ` variable is matched against
501505the pattern ` .qrCode(let productCode) ` here.
You can’t perform that action at this time.
0 commit comments