if/guard case let

  • case : pattern matching.

  • let : binds associated values

โญ๏ธ ๆณจๆ„๏ผš for case let ... where ๅŠ ๆขไปถ็š„ๆ–นๅผ่ทŸ if/guard case let ไธไธ€ๆจฃโ—๏ธ

// โญ if case let
//          โ•ญโ”€โ”€โ”€โ”€โ”€ โญ pattern โ”€โ”€โ”€โ”€โ”€โ•ฎ    โ†ฑ โญ value
if case let Media.movie(title, _, _) = movie { ... }

// โญ if case let
if case let .loaded(data) = state, 
   data.isEmpty                        // โญ additional conditions
{ ... }

// โญ guard case let
guard 
    case let .loaded(data) = state, 
    data.isEmpty                        // โญ additional conditions
else { ... }

Last updated