Comments (6)
➤ PM Bot commented:
Jira ticket: RCOCOA-2380
from realm-swift.
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.
from realm-swift.
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
#Preview {
return ContentView()
.environment(\.realm, ItemGroup.previewRealm) // <----- Causes crash
}
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 .environment
The preview should only be getting it's data from the ItemGroup.previewRealm
so even if the objects schema were to change, if the preview is refreshed, it would still pull data only from the realm defined in the previewRealm, right?
So what would trigger a migration if the app itself is not being run?
from realm-swift.
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?
from realm-swift.
@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)
class Item: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: ObjectId
@Persisted var itemName = ""
@Persisted var isFavorite = false
@Persisted var ownerId = ""
}
and then add a property - do NOT run the project
class Item: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: ObjectId
@Persisted var itemName = ""
@Persisted var isFavorite = false
@Persisted var ownerId = ""
@Persisted var test = "" // added property
}
and preview crashes.
from realm-swift.
@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.
-
Create a new macOS app, SwiftUI
-
Add Realm via SPM (per the documentation)
-
copy and paste the code in the Content View. Do NOT run the project
-
Preview will not work at this point. Go to the Project Target settings and delete App Sandbox and Hardened Runtime
-
Upon going back to the ContentView, Preview will refesh and show the globe with Hello, World. If you then look at ~/Library/Application Support/your project name, you will see the Realm files have been created - even though the app has not been run
-
In the ContentView file, go to the Item object model and add a property
@Persisted var test = ""
so it looks like this
class Item: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: ObjectId
@Persisted var itemName = ""
@Persisted var isFavorite = false
@Persisted var ownerId = ""
@Persisted var test = "" //add this
}
- At that point, preview will crash with a Fatal Error
Realm_Preview_Crash_PreviewReplacement_ContentView_1/ContentView.swift:71: Fatal error: Can't bootstrap item data: Migration is required due to the following errors:
- Property 'Item.test' has been added.
]
Then, delete the realm files that were generated:
-
delete the folder at
~/Library/Application Support/your project name
-
refresh preview, and it still crashes, even though the Realm files were deleted.
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.
from realm-swift.
Related Issues (20)
- Xcode 16: Write Blocks Risk Data Races Warnings HOT 11
- Update all uses of _unsafeInheritExecutor to use #isolation instead HOT 1
- Code sign our published xcframeworks HOT 1
- Update Binding for iOS 18's API changes HOT 1
- Switch to building RealmSwift in Swift 6 mode HOT 1
- Investigate explicitly built modules for RealmSwift HOT 1
- Add support for logging categories HOT 1
- After upgrading to 10.52.0 our app crashes on launch when we attempt to observe a collection HOT 4
- App crash for iOS 12 using 'RealmSwift', '~> 3.20.0' HOT 5
- Delete Realm if file is an unsupported version HOT 1
- Is it possible to fully deallocate the Memory used by Realm HOT 4
- Doesn't Map value type work at all? HOT 4
- Multiple methods named 'initWithValue:' found with mismatched result, parameter type or attributes v10.50.1 HOT 3
- ObjectId does not conform to SortableType - sorted(by:ascending:) not working as expected HOT 3
- Namespace DYLD, Code 1 Library missing HOT 2
- RealmSwift Crashing on Xcode 16 beta 2 when used in XCFramework as Dependency HOT 2
- Support "Cascading/Inheritable" Writes HOT 16
- Realm crash when accessing PersistableEnum HOT 13
- 极个别用户数据会莫名删除清空 HOT 2
- Query Syntax: Incorrect NSPredicate When Using `.values` on a Map Property HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from realm-swift.