2016-05-27 10 views
1

私はレルムのスキーマを移行しようとしていましたが、以下のようには思えません。 oldSchemaレルムの移行:オブジェクトをリストに移行

、私は次のようしている:newSchema

class Period: Object { 
    dynamic var weekday: Weekday! // this is just another Realm Object 
} 

を、私は平日(複数可)の一覧に平日を移動しようとしています。

class Period: Object { 
    let weekdays: List<Weekday> = List<Weekday>() 
} 

レルムの移行を実行する場合、どのように私はnewSchemaweekdaysリストにoldSchemaからweekdayオブジェクトを移動します。

ありがとうございました。

答えて

1

Realm設定の下で、移行ブロックを実行できます。

Realm.Configuration.defaultConfiguration = Realm.Configuration(
schemaVersion: 2, 
migrationBlock: { migration, oldSchemaVersion in 

    migration.enumerate(Period.className()) { oldObject, newObject in 
     // filter the versions where this change would take place 
     // if oldSchemaVersion < 1 { 
     // }... 
     newObject["weekdays"] = [oldObject["weekday"]]    
    }) 
+0

私が必要としたものに到達するには良いスタートでした。ありがとう。 – andyl

関連する問題