-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS: Realm Environment Injection Crashes Preview #8613
Comments
➤ PM Bot commented: Jira ticket: RCOCOA-2380 |
Hey, can you share the full repro project - it appears like someone else is opening a Realm with the same identifier but a different schema, so the schema validation logic kicks in, but it's not obvious from the shared code what could be culprit. |
Thanks @nirinchev. The entire project is the above code - it's local only so there would not be someone else opening the realm and there are no other apps accessing that projects directory or supporting files directory. I do have a followup question that may lead to the solution. Keep in mind that the project itself works, it's only the preview that's crashing
When a new, fresh project is first run, Realm creates the default.realm file with the objects schema. If the app is then quit, and the schema is changed in the project but the project is NOT run, the only 'code' that's doing anything is the XCode code that drives the preview with the injected The preview should only be getting it's data from the So what would trigger a migration if the app itself is not being run? |
I can't seem to repro this with the code provided. I can see a preview with a globe and "Hello world" below it and even if I update it to read some data from the Realm file, it still works just fine. Is it possible you have another instance of Xcode/your app opening an in-memory realm with the same identifier somewhere? |
@nirinchev Yes, I have the same result. However, do this: Add a property to the Item object but DO NOT RUN the project. Let the preview refresh and it will error out. Here's the Item object (per the original report above)
and then add a property - do NOT run the project
and preview crashes. |
@nirinchev I am still getting the same error as in the original post - and I am narrowing the issue and think it can be duplicated. One thing I noted is that on a 100% clean project, using the above code, without running the project, the #Preview generates the Realm files on disk. This apparently means that during development, changing an object schema, even if the added properties are not used anywhere, will crash preview without actually running any code.
Then, delete the realm files that were generated:
I thought perhaps adding a Migration (per the documentation) would help but without running the project, that migration doesn't run either. Deleting the realm folder and cleaning the build folder doesn't help. I did the above steps 4 times with the same result - My thinking is the preview should not be accessing any files on disk as an in memory realm is being injected. It's not clear (to me) what's causing the issue or how to handle changing an object model during development and have preview work. |
How frequently does the bug occur?
Always
Description
Injecting a realm into a view as an environment value crashes preview.
Stacktrace & log output
Can you reproduce the bug?
Always
Reproduction Steps
This is the entire project. Note the .environment injection in #Preview causes crash. With that commented out, preview works correctly.
That piece of code is taken from the documentation here Create a Realm with Data for Previews
Version
10.50.1
What Atlas Services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
macOS 14.2.1
Build environment
Xcode version: 15.4
Realm Database: 14.6.2
Dependency manager and version: SPM
The text was updated successfully, but these errors were encountered: