How the “case of protection” works for non-enumerations

Please explain why this works?

func howMany() -> Int {return 11}
guard case let output = howMany(), output > 10 else {return}

I understand how guard / if / while / for case let works with enums. Matching patterns is great. But there is no listing here, and that works too. What is a language construct that allows this?

(This example was taken from a book by Matt Neuburg.)

+4
source share
1 answer

This is the design if case. ( guardis simply negative ifif you understand what I mean.)

, if guard, case. switch, , ( ).

. fooobar.com/questions/719249/...

+2

Source: https://habr.com/ru/post/1689712/


All Articles