swift run循环'NSFastEnumerationIterator.Element'(又名'Any')不能转换为'UIView'

时间:2016-11-30 15:50:52

标签: ios uiview swift3

var _buttons : NSMutableArray = []
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {


    let location : CGPoint = gestureRecognizer.location(in: self)
    for subviews : UIView in _buttons {
        if subviews.frame.contains(location) {
            return false
        }
    }

    return true
}

我这样做但是它出现了错误'NSFastEnumerationIterator.Element' (aka 'Any') is not convertible to 'UIView'

我尝试将for subviews : UIView in _buttons替换为for subviews : UIView in _buttons as [AnyObject],但它不起作用。

我该怎么办?

1 个答案:

答案 0 :(得分:0)

您需要将自己的收藏集声明为var buttons: [UIView],以确保其仅包含UIView s