簡體   English   中英

二進制運算符'=='不能應用於類型'(Any)-> Int'和'Int'的操作數

[英]Binary operator '==' cannot be applied to operands of type '(Any) -> Int' and 'Int'

我希望索引等於1或2,但出現錯誤*

“二進制運算符'=='不能應用於類型'(Any)-> Int'和'Int'的操作數”

那我該如何解決呢?

那就是我的代碼

func onboardingWillTransitonToIndex(_: Int) {
        if index == 1 {
            if self.welkomBtn.alpha == 1 {
                UIView.animate(withDuration: 0.2, animations:  {
                    self.welkomBtn.alpha = 0
                })
            }
        }
    }

func onboardingDidTransitonToIndex(_: Int) {
    if index == 2 {
        UIView.animate(withDuration: 0.2, animations:  {
            self.welkomBtn.alpha = 1
        })
    }
}

功能應該像

func onboardingWillTransitonToIndex(_ index:Int)
func onboardingDidTransitonToIndex(_ index:Int) 

當前代碼中的index(Any) -> Int ,不能與1或2(屬於Int類型)進行比較

index不是Int,如果這是一個類變量,請確保其index : Int ,否則,請在function參數中指定。

該錯誤告訴您只能將IntInt進行比較,在這種情況下,index 不是 Int1是。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM