Sea*_*ean 4 objective-c realm ios
我正在尝试删除我的一个Realm对象中的属性,但是我不确定如何为此编写迁移.
我刚刚从我的对象的头文件中删除了该属性,但是这不起作用,因为我收到此错误:
由于未捕获的异常'RLMException'而终止应用程序,原因:'由于以下错误,对象类型'Stock'需要迁移: - 最新对象模型中缺少属性'percentageOn'.
我知道如何编写迁移添加字段,但如何删除一个?
大卫说的是对的.如果确保正确执行迁移,则Realm可以轻松处理已删除和添加的属性.除非您确实仍需要值,否则您percentageOn
甚至可以将迁移块留空,就像Realm网站上的示例一样:
// 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];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3017 次 |
最近记录: |