0

I recently released an app into production using Realm and then needed to add fields to two object types. With a synced realm and additive changes, I'm able to read and write correctly.

I spoke with one of the Realm team members on the forum and added

configuration: Realm.Configuration(schemaVersion: 1)

to my ObservedResults which used the newly updated types. This shouldn't be necessary, but I tried it anyway.

The thought was that this would perhaps deal with this error I am getting, but it hasn't helped.

When dismissing a .sheet where there is an ObservedResults on the parent screen behind the sheet, I get this error which is helpful to see in the SwiftUI.swift file:

"Migration is required due to the following errors: - Property 'FlaggedPost.hidden' has been added. - Property 'Post.visible' has been added."

I'm using Realm Cocoa 10.5.1

Any guidance on why a synced realm would be asking for a migration on an additive change or what I should be doing differently or if this is a bug?

Kurt
  • 3
  • 2
  • It’s a good idea to include code, errors and and structures as *text*, not links and images. That way, if they are needed in an answer, they can be copied and pasted. Also, if the links break, it would invalidate the question. See [images and links are evil](http://idownvotedbecau.se/imageofcode). Lastly, images are not searchable which may prevent future readers from locating the question. Also, take a look at [No Images Please](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) – Jay Oct 03 '21 at 14:36
  • I would suggest wrapping that try in a do: catch block to better handle errors. Also, what is causing the Fatal Error - is configurtion or Realm.Configuration.defaultConfiguration nil? more troubleshooting would help us to help you. – Jay Oct 03 '21 at 14:40

1 Answers1

0

@kurt the work around for this is to set the configuration in an environment value on the View that wraps the parent View.

ContentView().environment(\.realmConfiguration, Realm.Configuration(schemaVersion: 1))
Lee
  • 23
  • 1
  • 6
  • Thanks Lee. I have added this environment config on my ContentView() and then tried to add it directly to the parent view before the sheet is displayed. When the sheet is dismissed, it still crashes. This workaround may work for ObservedResults in general, but it doesn't seem to help in .sheet or .fullScreenCover Is it a requirement to also add this config in every @ObservedResults declaration? I had added it to every ObeservedResults based off this forum post: https://www.mongodb.com/community/forums/t/new-article-migrating-your-ios-apps-synced-realm-schema-in-production/122233/8 . – Kurt Oct 04 '21 at 14:28
  • Looks like this is a bug. Andrew at MongoDB was able to replicate it and this repo demonstrates the issue: https://github.com/ClusterDB/migrate-issue – Kurt Oct 07 '21 at 15:21
  • is this issue has been solved? – Abdurakhmon May 16 '23 at 11:42