title: How to migrate old properties into a new object with Realm Swift
body: <p>Previously, I had only one object that had every value that I needed. I "regrouped" them and made separate objects. I added properties with the type of the new objects to the original object.
  How can I assign the old property values to the object's properties?</p>
  
  <p>Here's the code for my objects:</p>
  
  <pre><code>class MainObject: Object {
      dynamic var id: Int = 0
      // Schema 0
      dynamic var otherId: Int = 0
      dynamic var otherStr: String = ""
  
      dynamic var anotherId: Int = 0
      dynamic var anotherD: Double = 0.0
      dynamic var anotherText: String = ""
  
      // Schema 1
      dynamic var otherObjectVar: OtherObject?
      dynamic var anotherObjectVar: AnotherObject?
  }
  
  // Schema 1
  class OtherObject: Object {
      dynamic var id: Int = 0
      dynamic var str: String = 0
  }
  class AnotherObject: Object {
      dynamic var id: Int = 0
      dynamic var d: Double = 0.0
      dynamic var text: String = ""
  }
  </code></pre>
  
  <p><em>(Changed variable names)</em></p>
  
  <p>I tried to use <code>convenience init(){}</code> but it didn't work. I also tried to assign an object instance to the newObject, but that didn't work either.
  Here's that code for easier understanding:</p>
  
  <pre><code>let other = OtherObject()
  other.id = 0
  other.str = oldObject["otherStr"] as! string
  newObject["otherObjectVar"] = other
  </code></pre>
  
  <p>How can I migrate the old properties into a new property which is another object?</p>
  
  <p>EDIT: Temporarily, I solved it with</p>
  
  <pre><code>let obj = migration.create(MainObject.className())
  migration.delete(obj)
  </code></pre>
  
  <p>but I don't think this is the right solution. So if anyone has a solution for this, I'd appreciate it.</p>