我需要在我的User模型中实现一个协议,该协议需要具有一些特殊属性。但是我想避免将它们存储/保存在Realm数据库中。
我没有在文档中看到是否有关键字。有没有办法避免保存一些属性?
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
答案 0 :(得分:21)
查看有关Ignoring properties的RealmSwift文档。该部分包含一些示例代码:
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"]
}
}