I am currently using Realm Swift 1.0.1.
Say you have a Realm Objectthat has another Realm Objectas a property:
import RealmSwift
class Car: Object {
dynamic var id = 0
override static func primaryKey() -> String? {
return "id"
}
dynamic var model = ""
}
class Garage: Object {
dynamic var id = 0
override static func primaryKey() -> String? {
return "id"
}
dynamic var carStored: Car?
}
If you then create new objects Carand Garage, and Caris a property Garage... but just write a new one Garagein Realm, for example ...
let teslaCar = Car()
teslaCar.id = 1
teslaCar.model = "Tesla"
let myGarage = Garage()
myGarage.id = 1
myGarage.carStored = teslaCar
let realm = try! Realm()
try! realm.write {
realm.add(myGarage, update: true)
}
... will record a cascade as well as save teslaCarin Realmas well myGarage?
Realm Swift operators write: https://realm.io/docs/swift/latest/#writes
source
share