Realm,避免存储一些属性 [英] Realm, avoid to store some property
本文介绍了Realm,避免存储一些属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的用户模型中实现一个协议,它需要有一些特殊的属性.但我想避免将它们存储/持久化在 Realm 数据库中.
I need to implement a protocol in my User model, which need to have some special properties. But I'd like to avoid them to be stored/persisted in Realm database.
我在文档中没有看到是否有关键字.是否有避免保存某些属性的技巧?
I didn't see in the documentation if there was a keyword for this. Did there is a trick to avoid saving some properties ?
public final class User: Object, Mappable, AvatarImageViewDataSource {
dynamic var id: Int = 0
dynamic var desc: String? = nil
dynamic var email: String? = nil
dynamic var firstName: String? = nil
dynamic var lastName: String? = nil
...
public var myPropertyIDontWantToSave: String? = nil // I don't want this to be stored
推荐答案
查看 RealmSwift 文档关于 忽略属性.该部分包含一些示例代码:
Check out the RealmSwift docs about Ignoring properties. There is some sample code included on that section:
class Person: Object {
dynamic var tmpID = 0
var name: String { // read-only properties are automatically ignored
return "\(firstName) \(lastName)"
}
dynamic var firstName = ""
dynamic var lastName = ""
override static func ignoredProperties() -> [String] {
return ["tmpID"]
}
}
这篇关于Realm,避免存储一些属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文