Why force unwrapping is required in case of enum and switch?

后端 未结 3 949
南笙
南笙 2020-12-03 16:51

I have notice weird swift behaviour, because in my opinion colours variable shouldn\'t be force unwrapped in case of switch written below, but without unwrapping compiler sh

3条回答
  •  温柔的废话
    2020-12-03 17:31

    Instead of using :

    var colours: Colours!
    colours = .Red
    

    Simply use

    var colours = Colours.Red
    

    That should do the trick.

提交回复
热议问题