我需要在迁移过程中从域中删除对象。
我有一个包含以下内容的AccountManager:
func logOut() {
let realm = try! Realm()
try! realm.write {
realm.delete(realm.objects(Account.self))
realm.delete(realm.objects(Address.self))
... // Other deletions
}
}
但是每当我在迁移块中使用logOut()函数时,它总是失败。
let config = Realm.Configuration(
schemaVersion: 11,
migrationBlock: { migration, oldSchemaVersion in
if (oldSchemaVersion < 11) {
// Delete objects from realm
AccountManager().logOut() // DOESN'T WORK
}
})
Realm.Configuration.defaultConfiguration = config
我绝对需要用户在此更新后重新登录 - 有没有办法在迁移块中执行这些删除操作?