Android有一种方法可以实现这一点,但我仍然对接近iOS感到困惑。我不想每次有新更新时都进行迁移,所以如果是这样,我更喜欢 clear db 重新开始。
我发现这个问题与此相关
我只能使用此代码进行迁移吗?
// Notice setSchemaVersion is set to 1, this is always set manually. It must be
// higher than the previous version (oldSchemaVersion) or an RLMException is thrown
[RLMRealm setSchemaVersion:1
forRealmAtPath:[RLMRealm defaultRealmPath]
withMigrationBlock:^(RLMMigration *migration, uint64_t oldSchemaVersion) {
// We haven’t migrated anything yet, so oldSchemaVersion == 0
if (oldSchemaVersion < 1) {
// Nothing to do!
// Realm will automatically detect new properties and removed properties
// And will update the schema on disk automatically
}
}];