我正在使用
Xcode 7.2,Swift 2.1.1.我在下面有一个Realm模型对象
class B: Object {
dynamic let lists = List<A>()
}
但Swift编译器给出了一个错误说:
Property cannot be marked as dynamic because its type cannot be represented in Objective-C
我看到Realm的文档说:
Realm model properties need the dynamic var attribute in order for these properties to become accessors for the underlying database data.
There are two exceptions to this: List and RealmOptional properties
cannot be declared as dynamic because generic properties cannot be
represented in the Objective-C runtime,which is used for dynamic
dispatch of dynamic properties,and should always be declared with let
但是现在似乎没有解决这个问题.我错过了什么?
您引用的文档包括以下内容(强调我的):
List and RealmOptional properties cannot be declared as dynamic because generic properties cannot be represented in the Objective-C runtime,[…],and should always be declared with let
.
这意味着您的属性应该如下声明:
let lists = List<A>()
Realm Swift文档最近获得了property declaration cheatsheet,希望能够澄清不同类型声明的要求.