加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 02:23:56 所属栏目:百科 来源:网络整理
导读:我正在使用 Xcode 7.2,Swift 2.1.1.我在下面有一个Realm模型对象 class B: Object { dynamic let lists = ListA() } 但Swift编译器给出了一个错误说: Property cannot be marked as dynamic because its type cannot be represented in Objective-C 我看到R
我正在使用 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,希望能够澄清不同类型声明的要求.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读