在领域迁移期间从其他表获取属性值

时间:2018-09-12 05:22:30

标签: swift realm realm-migration

是否有文档记录的方式或示例来查询或从其他表中获取属性的值?

现在我有:

Type

然后我在Realm的迁移模块中称它为

private func getFullnameFromPerson(_ migration: Migration, _ userId: String) -> String {
    var fullname = ""
    migration.enumerateObjects(ofType: Person.className(), {oldObject, newObject in
        let _userId = newObject?["userId"] as? String
        if _userId == userId {
            let firstname = oldObject?["firstName"] as? String ?? ""
            let lastname = oldObject?["lastName"] as? String ?? ""
            fullname = "\(firstname) \(lastname)"
        }
    })
    return fullname
}

这样可以吗?还是应该有更适当的方法?

0 个答案:

没有答案