领域-Swift存储协议类型 [英] Realm - Swift store a protocol type

查看:99
本文介绍了领域-Swift存储协议类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下结构:

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

}

是否可以在属性中存储某些内容? 今天返回零.如果添加动态,则会返回错误:

Is there a way of storing something in attribute? Today is returning nil. If I add dynamic it returns the error:

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

有什么方法可以存储符合协议的属性吗?

Is there any way to store properties that conform to a Protocol as that?

推荐答案

否.领域属性是单态的,领域需要知道在初始化时将链接到的具体对象类型是什么.

No. Realm properties are monomorphic, and Realm needs to know what the concrete object type that will be linked to is at initialization time.

这篇关于领域-Swift存储协议类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆