I have a realm database Object as defined in the class
class TPDailyRashifal: Object, Mappable {
public required convenience init?(map: Map) {
self.init()
mapping(map: map)
}
dynamic var rashi: String = ""
dynamic var rashiDetail: String = ""
public func mapping(map: Map) {
rashi <- map["rashi"]
rashiDetail <- map["rashifal"]
}
override static func primaryKey() -> String {
return "rashi"
}
}
I would like to add these three variables in my Object as follows
dynamic var date: String = ""
dynamic var fallIds: String = ""
dynamic var rating: Int = 0
I know my mapping function would have to be modified and to add followings.
date <- map["date"]
fallIds <- map["fallIds"]
rating <- map["rating"]
But my
dynamic var rashi: String = ""
definition has to change to
dynamic var rashi: Int = 0
In my Appdelegate, applicationDidFinishLaunchingWithOptions function, I have written
Realm.Configuration.defaultConfiguration = Realm.Configuration(
schemaVersion: 1,
migrationBlock: { migration, oldSchemaVersion in
if (oldSchemaVersion < 1) {
print("Schema Version 0")
// The enumerateObjects(ofType:_:) method iterates
// over every Person object stored in the Realm file
migration.enumerateObjects(ofType: TPDailyRashifal.className()) { oldObject, newObject in
// combine name fields into a single field
/*
To add these variables during migration
dynamic var date: String = ""
dynamic var fallIds: String = ""
dynamic var rating: Int = 0
*/
let oldRashi = oldObject?["id"] as? Int
// let newRashiId =
}
}
})
I am confused to where should I begin adding the new variables in the Realm Object. I have referred to other questions, but I couldn't catch up with them.