Zakaria
Zakaria

Reputation: 1090

How to access a List property of a swift class from an Objective C class

I have this swift model class (using Realm) that has a simple String property and a List of strings. I can easily access the string property from an Objective-C class, but it doesn't seem to work when I try to access the List property.

Code:

class MyClass: Object, Mappable {

   dynamic var stringProperty: String?
   let listOfStrings = List<StringValue>()

}

I tried creating a getter method that returns a simple array from the List property, but I wonder if there is a better way.

Upvotes: 1

Views: 162

Answers (1)

bdash
bdash

Reputation: 18308

One of the first things that the Realm Swift documentation says is:

If you’re looking to use Realm from Objective‑C, or from mixed Objective‑C & Swift apps, please see Realm Objective‑C instead. The Realm Objective‑C and Realm Swift APIs are not interoperable and using them together is not supported.

There is some limited, unofficial support for interoperability with Objective-C available that may help you, but it's really intended for only very narrow use cases (primarily to allow writing frameworks that wish to support models written in both Realm Objective-C and Realm Swift). The general advice is that if you want to access your Realm models from both Objective-C and Swift, use Realm Objective-C.

Upvotes: 1

Related Questions