I'm getting a casting error in a migration to change property Double to List<CustomObject>

How can I create a migration to change discount:Double to discounts:List<Discount>() based on the following code?

Here is the Existing Object: This is how my Realm Object looks right now.

class Item:Object{
    @objc dynamic var itemName:String = "Some Name"
    @objc dynamic var discount:Double = 0 // need to change this property

Here is how I’m trying to make the change.

New Object:

class Discount: Object {
    @objc dynamic var name:String = "Discount Name"
    @objc dynamic var discount:Double = 0.0

Modified Object with one-to-manyrelation.

class Item:Object{
    @objc dynamic var itemName:String = "Some Name"
    let discounts = List<Discount>()


    Realm.Configuration.defaultConfiguration = Realm.Configuration(
        schemaVersion: 3,
        migrationBlock: { migration, oldSchemaVersion in
            if (oldSchemaVersion < 3) {
                migration.enumerateObjects(ofType: Item.className()) { oldObject, newObject in

                    let oldDiscount = oldObject!["discount"] as! Double

                    let discount = Discount()
                    discount.amount = oldDiscount
                    let discounts = newObject!["discounts"] as! List<Discount>

I’m getting error:

Could not cast value of type RealmSwift.List<RealmSwift.DynamicObject>(0x1c8910068) to RealmSwift.List<AppName.Discount> (0x1c890f6a0).

What am I doing wrong?

Cross post to this question with an answer on SO

Casting error in Realm migration to change property Double to List

Thanks a lot for your help and sorry about the double posting but I usually post in one and if I don’t get an answer in a day or so I tried other forums.