swift - sort an array of objects by their optional boolean property without force unwrapping

前端 未结 6 575
旧巷少年郎
旧巷少年郎 2021-01-02 00:02

I can sort this array of store objects by their \'flagship\' boolean property, but how can I safely unwrap the \'flagship\' property first?

le         


        
6条回答
  •  梦毁少年i
    2021-01-02 00:45

    How about:

    $0.flagship == true && $1.flagship != true
    

    The left side will succeed if the value is not nil and is true, the right side will succeed if the value is either nil or false.

提交回复
热议问题