1

I have updated the Realm object in swift. I simply want to delete the schema and create a new one in case the app has the older version.

To achieve this I am using the following code:

   lazy var realm = try! Realm(configuration:Realm.Configuration(deleteRealmIfMigrationNeeded: true))

But it results in SchemaMismatchException at this particular line.

I have also tried this and code sample of this. But I get same error at the line of declaration of Realm object.

Can anybody give the working code of this?

Community
  • 1
  • 1
vishalaksh
  • 2,054
  • 5
  • 27
  • 45
  • bdash is correct! I just tried [this](https://stackoverflow.com/a/43817264/2296630) sampled and worked right! – mourodrigo Jun 06 '17 at 13:27

1 Answers1

0

SchemaMismatchException is an exception that Realm throws internally. If deleteRealmIfMigrationNeeded is true the exception is caught and the Realm is removed. If it is set to false, the exception is translated into an NSError. Seeing the exception be thrown in your case is expected.

bdash
  • 18,110
  • 1
  • 59
  • 91