Josh Stern Josh Stern - 5 months ago 40
Swift Question

linkingObjectsProperties override from swift 2.0

I am using realm-cocoa(v1.0.1) with a Swift 2.0 project (need objective-c interoperability) and am having trouble overriding the linkingObjectsProperties method.

I've followed the Realm documentation (https://realm.io/docs/objc/latest/#inverse-relationships) and defined my function override in my RLMObject subclass as follows:

override class func linkingObjectsProperties() -> NSDictionary {
return ["owners": RLMPropertyDescriptor(withClass: Person.self, propertyName: "dogs")]
}


The compiler then complains, saying "Method does not override any method from its superclass".

If I prefix the definition with @objc, the error changes to "Overriding method with selector 'linkingObjectsProperties' has incompatible type '() -> NSDictionary'

Any ideas?

Thanks!

Answer

+[RLMObject linkingObjectsProperties] is exposed to Swift as class func linkingObjectsProperties() -> [String : RLMPropertyDescriptor]. Updating your override to match that signature should do the trick.

Comments