База данных Realm для iOS выдает ошибку несоответствия схемы. При условии, что версия 84 схемы меньше последней установленной версии 86 - PullRequest
0 голосов
/ 04 июня 2018

Я недавно обновил свой проект и с тех пор у меня возникла проблема с Realm.Код выглядит следующим образом:

    MyNetworkManager.sharedNetworkManager.performNetworkOperation(url: MyEndpoint().homepage(), httpmethod: .get, parameters: requestDict) { response in
        let realm = try! Realm()
        try! realm.write {
            let JSON = response.result.value as AnyObject
            realm.create(HomePageData.self, value: JSON, update: true)
        }

Показана следующая ошибка:

    Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: 
    Error Domain=io.realm Code=1 "Provided schema version 84 is less than last set 
    version 86." UserInfo={NSLocalizedDescription=Provided schema version 84 is 
    less than last set version 86., Error Code=1}

Я читал другие ответы по той же проблеме, но не нашел ничего похожего.Я новичок в Realm в целом, пожалуйста, дайте мне знать, как лучше всего это решить.

Сведения о проекте:

  1. Язык - Swift 3 и Objective C по частям
  2. Область для Swift используется для DB
  3. Версия Xcode - 9.2

1 Ответ

0 голосов
/ 04 июня 2018

Вы устанавливаете старую версию приложения на новую версию (downgrade)

Вот что вызывает эту проблему, просто попробуйте перенести вашу БД

 var 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: 87,

                // 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
                    // We haven’t migrated anything yet, so oldSchemaVersion == 0
                    if (oldSchemaVersion < 86) {
                        // Nothing to do!
                        // Realm will automatically detect new properties and removed properties
                        // And will update the schema on disk automatically
                    }
            })

            // Tell Realm to use this new configuration object for the default Realm
            Realm.Configuration.defaultConfiguration = config
...