如何检查在
Swift的while循环中没有?我收到错误:
var count: UInt = 0 var view: UIView = self while view.superview != nil { // Cannot invoke '!=' with an argument list of type '(@lvalue UIView,NilLiteralConvertible)' count++ view = view.superview } // Here comes count...
我正在使用Xcode6-Beta7.
你的代码无法编译.零只能出现在可选项中.
您需要使用可选的var视图来声明视图:UIView? = self.superview.
然后在while循环中与nil进行比较.
原文链接:https://www.f2er.com/swift/318867.html您需要使用可选的var视图来声明视图:UIView? = self.superview.
然后在while循环中与nil进行比较.
var count: UInt = 0 var view: UIView? = self.superview while view != nil { // Cannot invoke '!=' with an argument list of type '(@lvalue UIView,NilLiteralConvertible)' count++ view = view!.superview }
或者做一个约束力,但在这里似乎没有必要,我想.