Binary operator '<' cannot be applied to two 'Int?' operands

后端 未结 3 1037
一向
一向 2020-12-06 07:34

Good evening lovely community,
this is my first post, please have mercy, if I do something wrong.
I know there are some similar questions here, but I doesn\'t under

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 08:01

    Well, by using guard statement you can check if both values are not nil, and converting it to Int typ

        guard let value_one = Int(goalPlayerOne), let value_two = Int(goalPlayerTwo) else {
            print("Some value is nil")
            return
        }
    

    so you can safely compare two values.

        if value_one < value_two {
           //Do something
        }
    

提交回复
热议问题