领域 - Swift 存储协议类型

Realm - Swift store a protocol type

我有以下结构:

class Entity : Object {
    dynamic var Id = 0
    dynamic var Title = ""
    dynamic var Subtitle = ""
    var atttribute : MyProtocol?

}

有没有办法在属性中存储一些东西? 今天是返回零。如果我添加动态它 returns 错误:

Property cannot be marked dynamic because its type cannot be represented in Objective-C

有没有办法存储符合协议的属性?

没有。 Realm 属性是单态的,Realm 需要在初始化时知道​​将链接到的具体对象类型是什么。