Reputation: 199
I have a reminder object, that I just modified. Here is the original version:
class Reminder: Object {
@objc dynamic var title = ""
@objc dynamic var parents = ""
@objc dynamic var lists = "All"
@objc dynamic var labels = "All"
@objc dynamic var priority =
@objc dynamic var notes = ""
@objc dynamic var reminderType = .none
}
and here is the new version:
class Reminder: Object {
@objc dynamic var title = ""
@objc dynamic var parents = ""
@objc dynamic var lists = "All"
@objc dynamic var dueDate = 0.0
@objc dynamic var reminderDate = 0.0
@objc dynamic var reminderLocation = ""
@objc dynamic var labels = "All"
@objc dynamic var priority = 1
@objc dynamic var notes = ""
}
I have implemented a migration block didFinishLaunchingWithOptions
method of the AppDelegate. Here it is:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
///Realm migration
let config = Realm.Configuration(
// Set the new schema version. This must be greater than the previously used
// version (if you've never set a schema version before, the version is 0).
schemaVersion: 2,
// Set the block which will be called automatically when opening a Realm with
// a schema version lower than the one set above
migrationBlock: { migration, oldSchemaVersion in
if oldSchemaVersion < 2 {
}
}
)
Realm.Configuration.defaultConfiguration = config
let _ = try! Realm()
return true
}
According to the documentation, I believe that it should be a functional migration. However, I get the following error while compiling the app:
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=10 "Migration is required due to the following errors:
- Property 'Reminder.reminderLocation' has been added.
- Property 'Reminder.reminderDate' has been added.
- Property 'Reminder.dueDate' has been added.
- Property 'Reminder.reminderType' has been removed."
What should I change in my migration block?
Thank you in advance
Upvotes: 0
Views: 795
Reputation: 512
This exception will be thrown when stored data doesn’t match the model you have in code.
You shouldn’t need to do anything in the migration block, however you will need to trigger a migration by updating the value of Realm.Configuration.schemaVersion
, e.g.:
schemaVersion: 3,
Upvotes: 1