【问题标题】:Swift 1.2 -> NSSet -> incompatible type [duplicate]Swift 1.2 -> NSSet -> 不兼容的类型 [重复]
【发布时间】:2015-04-16 04:25:15
【问题描述】:

好的,Swift 1.2 发生了什么?我最近更新了,突然我的项目全是红色的。是否删除了与 NSSet 的兼容性或什么?我该如何解决这个问题?

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

结果:

Overriding method with selector 'touchesBegan:withEvent:' has incompatible type '(NSSet, UIEvent) -> ()'

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    请不要将 NNsets 现在声明为:

     func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
    

    请尝试以下代码进行覆盖

      override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    
            // ...
        }
    

    【讨论】:

      【解决方案2】:

      将 NSSet 更改为 Set。 Swift 现在拥有自己的原生集合,并将 NSSet 连接到它们,就像它处理数组和字符串一样。

      【讨论】:

        猜你喜欢
        • 2020-01-16
        • 1970-01-01
        • 2020-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-30
        • 1970-01-01
        相关资源
        最近更新 更多