Kingdom: Swift `let` property cannot be marked as dynamic

I am using Xcode 7.2, Swift 2.1.1. I have a Realm model object below

class B: Object { dynamic let lists = List<A>() } 

But the Swift compiler gives me an error:

A property cannot be marked as dynamic because its type cannot be represented in Objective-C

I saw the Realm documentation that says:

The properties of the Realm model require the dynamic attribute var to make these properties available to the underlying database data.

There are two exceptions: List and RealmOptional properties cannot be declared dynamic, because common properties cannot be represented at run time by Objective-C, which is used to dynamically send dynamic properties and should always be declared using let

But the let declaration doesn't seem to resolve this case right now. What am I missing?

+5
source share
1 answer

The documentation below contains the following (highlighting):

The list and properties of RealmOptional cannot be declared dynamic , since general properties cannot be represented at runtime of Objective-C [...] and must always be declared with let .

This means that your property should be declared as follows:

 let lists = List<A>() 

The Realm Swift documentation has recently received a property error announcement , which I hope will clarify the requirements for various types of declarations.

+3
source

Source: https://habr.com/ru/post/1240746/


All Articles