Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios ';NSSet?&x27;不包含名为';发电机&x27;_Ios_Swift_Nsset - Fatal编程技术网

Ios ';NSSet?&x27;不包含名为';发电机&x27;

Ios ';NSSet?&x27;不包含名为';发电机&x27;,ios,swift,nsset,Ios,Swift,Nsset,我正在覆盖视图的命中测试行为 override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? { var touches:NSSet? = event?.allTouches() for touch in touches { //look at each touch } } 我需要检查触摸阶段是否

我正在覆盖视图的命中测试行为

 override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView?
    {
        var touches:NSSet? = event?.allTouches()
        for touch in touches
        {
            //look at each touch
        }
    }
我需要检查触摸阶段是否开始。然而,我似乎无法重复所有的接触

我得到了错误

'NSSet?' does not contain a member called 'Generator'
我假设这意味着我不能像迭代数组一样迭代NSSet


您知道Swift中迭代NSSet的正确语法吗?

问题是您试图迭代可选集。您需要先将其展开。

问题是您试图在可选集上迭代。您需要先将其展开。

alltouchs
返回可选的
NSSet
,因此必须先将其展开-我建议使用如下可选绑定:

    if let touches = event?.allTouches() {
        for touch in touches
        {
            //look at each touch
        }
    }

alltouch
返回可选的
NSSet
,因此必须先将其展开-我建议使用如下可选绑定:

    if let touches = event?.allTouches() {
        for touch in touches
        {
            //look at each touch
        }
    }

您需要打开您的可选包装吗?尝试
触摸屏?
是的,刚刚尝试过它工作我爱我一些选项:-错误消息中的问号(如
NSSet?
)通常是相关的!您需要打开您的可选包装吗?尝试
触摸屏?
是的,刚刚尝试过它工作我爱我一些选项:-错误消息中的问号(如
NSSet?
)通常是相关的!真的很惊讶这件事从我身边溜走了!真的很惊讶这件事从我身边溜走了!