在Object子类和它自己的子类上实现ignoredProperties()

bol*_*iva 3 realm swift

我是Realm的新手.我正在创建我的模型,其基类继承自Object,以及此基类的自定义子类.我的模型要求基类通过覆盖静态ignoredProperties()方法声明一些属性被忽略.当尝试在某些基类子类上覆盖该方法时,我得到一个Swift编译器错误,指出Class方法会覆盖'final'类方法.我没有将我的基类实现标记为final.我不知道这是否是Realm的当前限制,但我似乎无法找到任何对此问题的引用.

我的代码看起来像这样:

class Base: Object {
    // properties declarations

    override static func ignoredProperties() -> [String] {
        return ["someProperty"]
    }
}

class SomeModel: Base {
    // properties declarations

    // compiler error here
    override static func ignoredProperties() -> [String] {
        var ignoredProperties = super.ignoredProperties()
        ignoredProperties.append("someOtherProperty")
        return ignoredProperties
    }
}
Run Code Online (Sandbox Code Playgroud)

任何想法或建议?我目前正在使用CocoaPods的最新Realm,当前的Xcode(7.2.1)和最新的Swift.

bda*_*ash 7

您已声明ignoredProperties为:

override static func ignoredProperties() -> [String]
Run Code Online (Sandbox Code Playgroud)

它应该是:

override class func ignoredProperties() -> [String]
Run Code Online (Sandbox Code Playgroud)

static子类不能覆盖函数.class功能可以.