Binary operator '===' cannot be applied to operands of type 'Any?' and 'UIBarButtonItem!'

后端 未结 2 1162
孤独总比滥情好
孤独总比滥情好 2020-12-29 21:27

The following code used to be able to compile in swift 2.2, no longer in swift 3.0. How do we fix this?

Error: Binary operator \'===\' cannot be appl

2条回答
  •  长情又很酷
    2020-12-29 22:22

    As the error message is saying. In Swift 3, Objecitve-C id is imported as Any, and you cannot call any operations for Any including ===, without explicit cast.

    Try this:

    if sender as AnyObject? === saveButton {
    

    (All the same for other sender comparison.)

    And remember, in Swift 3, as AnyObject has become one of the most risky operations, you should not use as AnyObject in other cases.

提交回复
热议问题