小编dce*_*dce的帖子

Swift重写静态方法编译错误

我有这两个快速的课程:

class A {    
    static func list(completion: (_ result:[A]?) -> Void) {
        completion (nil)
    }        
    static func get(completion: (_ result:A?) -> Void) {
        completion (nil)
    }
}


class B: A {    
    static func list(completion: (_ result:[B]?) -> Void) {
        completion (nil)
    }    
    static func get(completion: (_ result:B?) -> Void) {
        completion (nil)
    }        
}
Run Code Online (Sandbox Code Playgroud)

尝试编译这会引发错误"覆盖声明需要'覆盖'关键字",但仅适用于B类的'get'方法.'list'方法编译良好.[B]有什么区别?和B?对于这种情况下的编译器?

编辑:另请注意,无法添加"覆盖".我收到错误'无法覆盖静态方法'.

static compiler-errors compilation swift

9
推荐指数
1
解决办法
7438
查看次数

标签 统计

compilation ×1

compiler-errors ×1

static ×1

swift ×1