With Realm 5.4.0 I'm trying to migrate:
public final class MyObject: Object {
public let tags = List<String>()
}
to
public final class MyObject: Object {
public let tagIds = List<String>()
}
Therefore I wanted to write a migration block like this:
migration.enumerateObjects(ofType: "MyObject") { oldObject, newObject in
let tags = [String: String]() // filled earlier
let oldTagList = oldObject!.dynamicList("tags")
let newTagList = newObject!.dynamicList("tagIds")
oldTagList.forEach { tag in
if let id = tags[tag as String] { // this does not compile (1)
newTagList.append(id) // this does not work (2)
}
}
}
From the oldTagList I get DynamicObjects which cannot be casted to strings (1). I was able to solve this problem by a very ugly workaround:
let oldTagList = unsafeBitCast(oldObject!["tags"] as! List<DynamicObject>, to: List<String>.self)
What I was not able to solve is to add the id string to newObjects tagIds list (2).
I tried to cast the list the same way than oldObjects tags list but that throws an EXC_BAD_ACCESS error.
How can I migrate / convert the content of a List<String> into another List<String>?