微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

领域:Swift`let`属性不能标记为动态

我正在使用 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,希望能够澄清不同类型声明的要求.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐