Value binding = magic?

I am not quite sure how Value binding works in the example provided on page 40.

We do not explicitly set the constant unknownCode to the value of statusCode, yet swift automatically sets the value for us.

I am confused about how swift knows what to do here.

Hey dmc! When the statusCode variable fails to match any of the cases in the switch statement it is caught by the final statement, case let unknownCode:. This is where the value binding happens.

Think of it like this: Lets say statusCode = 419. The switch statement then tries to match 419 to the first 5 of its cases. When it fails to do so, it says “Okay, I don’t know what do with this, but I have this thing called unknownCode and that is a good enough match for me.” Basically saying, in this case let unknownCode = statusCode.

Hope that makes some sense!

Good luck!