![](/img/trans.png)
[英]Binary operator '>=' cannot be applied to operands of type 'Any' and '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參數中指定。
該錯誤告訴您只能將Int
與Int
進行比較,在這種情況下,index 不是 Int
, 1
是。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.