Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm, avoid to store some property

Tags:

swift

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
like image 812
Lory Huz Avatar asked Nov 07 '16 18:11

Lory Huz


1 Answers

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"]
  }
}
like image 140
Orlando Avatar answered Nov 06 '22 07:11

Orlando