您好我的项目中有一些代码,下面的代码会发出警告;
private var viewController: UIViewController? {
for var next:UIView? = self.superview; next != nil; next = next?.superview {
let responder = next?.nextResponder()
if let vc = responder as? UIViewController {
return vc
}
}
return nil
}
下面的警告线
for var next:UIView? = self.superview;下一个!=无; next = next?.superview {
我该如何解决?
答案 0 :(得分:1)
以下是如何使用while
周期重写代码:
var viewController: UIViewController? {
var next: UIView? = self.superview
while next != nil {
let responder = next?.nextResponder()
if let vc = responder as? UIViewController {
return vc
}
next = next?.superview
}
return nil
}