大卫说的是正确的。如果您确保正确执行迁移,则Realm可以轻松处理已删除和添加的属性。除非你居然还需要percentageOn
的价值,你甚至可以离开迁移块空就像在领域网站的例子:
// Inside your [AppDelegate didFinishLaunchingWithOptions:]
// 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, NSUInteger 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
}
}];
// now that we have called `setSchemaVersion:withMigrationBlock:`, opening an outdated
// Realm will automatically perform the migration and opening the Realm will succeed
[RLMRealm defaultRealm];
来源
2015-06-09 13:28:48
TiM
当然你不能直接做没有结果。解决方案1:删除U这样的属性,并从模拟器中删除应用程序。这解决了数据库不一致的问题。解决方案2:您的应用正在投入生产,用户已经在使用它。因此,您需要执行迁移以不影响您的客户。请阅读文档在这种情况下该怎么做:https://realm.io/docs/objc/latest/#migrations – David