I added a new Class ,newClass, to my Realm file through Realm Studio to allow users to manage an array of items. I also created swift file to manage the new class in XCode.
Since running the app immediately after doing the above, all my data from the firstClass, has disappeared (not a problem the user adds all data in this class on startup, I can repopulate whilst testing the app.)
My app now crashes whenever it reaches any code let realm = try! Realm(). I have commented out or removed references to these to see if it is a localised problem, but it still continuous to crash with the following similar errors depending on the VC it crashes on when during let realm = try! Realm().
schema version 1
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=1 "Provided schema version 0 is less than last set version 1." UserInfo={NSLocalizedDescription=Provided schema version 0 is less than last set version 1., Error Code=1}: file /Users/UserName/Desktop/AppName/AppName/Custom VC's/AddDataToRealmViewController.swift, line 168
2020-06-27 13:23:10.481817+0100 AppName[4498:173994] Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=1 "Provided schema version 0 is less than last set version 1." UserInfo={NSLocalizedDescription=Provided schema version 0 is less than last set version 1., Error Code=1}: file /Users/UserName/Desktop/AppName/AppName/Custom VC's/AddDataToRealmViewController.swift, line 168
After doing a little bit of reading around, it suggest I need to migrate my realm file to the new schema? Before I attempt this, would this be the correct course of action to take?
Related
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error:
Error Domain=io.realm Code=1 "Provided schema version 0 is less than
last set version 1." UserInfo={NSLocalizedDescription=Provided schema
version 0 is less than last set version 1., Error Code=1}
Getting this error when I try to add new property in Realm
Not finding any solution for this in swiftui
That's a normal error you will receive during development as you are changing your model and properties around.
The schema version is set to 1 (or it was set to 1) and then you modified an object so you should set schema version to 2 via a migration.
From the docs
Realm Database can automatically migrate added properties, but you
must specify an updated schema version when you make these changes.
If you're just in development, you could also just delete the Realm file and the objects will be built again with schema version 1.
Please see the documentation for Realm Migrations.
We've do that a LOT during the early stages of development so we have a button in our UI that just deletes the Realm files - keeping in mind that upon app start, you cannot touch the realm file for this to work. Once you've touched it, it's 'open' and cannot be deleted through code.
func deleteRealm() {
do {
//return the config pointing to where the realm file is located - we
// keep ours in the project folder initially
let config = gGetConfig()
let isSuccess = try Realm.deleteFiles(for: config)
print("deleted realm: \(isSuccess)")
} catch let err as NSError {
print(err.localizedDescription)
}
}
Edit: Sometimes you can nil the Realm out and then delete it via code but Realm is quite stubborn and sometimes that doesn't work either.
I just updated my Xcode to Version 14.1 (14B47b) from version 13.4. When I try to run my SwiftUI project in the live preview, the "Abort Trap" errors showed everywhere in the project.
Part of the error log is as below:
CompileSwift normal x86_64 /Users/apple/Downloads/SwapSpot/SwapU/ViewModels/ItemVMs/ItemGridViewModel.swift (in target 'SwapU' from project 'SwapU')
unknown:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
unknown:0: note: SmallVector unable to grow. Requested capacity (4294967297) is larger than maximum value for size type (4294967295)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
I found a post that answers as such:
We will not observe "Abort: trap 6", if under Build Settings, we are using "Optimize for Speed" in Debug, instead of "No Optimization"
We can also avoid "Abort: trap 6", if we change the following code
guard let batchUpdateResult = batchUpdateResult else { return }
to
guard let batchUpdateResult2 = batchUpdateResult else { return }
I tried both methods mentioned above. Renaming the guard let variable did not work at all. Changing the optimization level in the target removed all the Abort Trap errors, and the project runs successfully in the simulator.
However, the live preview stopped working due to the optimization level. The new error is stated below:
OptimizationLevelError: not building -Onone
"SwapU.app" needs -Onone Swift optimization level to use previews
I believe this is a swift compiler error. Can anyone help me avoid this while keeping the live preview working?
I am trying to read the content of a .csv file using the framework CreateML to read csv data.
Fhe following code generates an error even though the file exists:
let csvURL = URL(fileURLWithPath: "/Volumes/MAC HDD/Data/Data.csv")
let fm = FileManager()
if (fm.fileExists(atPath: csvURL.path)) {
let dataTable = try! MLDataTable(contentsOf: csvURL)
// accessing first column
let col_1 = Array.init(dataTable["col1"])
}
I get the following error message:
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: CreateML.MLCreateError.generic(reason: "No files corresponding to the specified path (file:///Volumes/MAC%20HDD/Data/Data.csv)")
I have checked nearly everything but can't get any results. What am I doing wrong?
I found out by my self what the problem is.
I have implemented this code in a Xcode project to read csv data, but the CreateML framework is just working for Xcode Playground and not within a Xcode Project! It was mentioned at the end of the WWDC 2018 session video 703.
The code example above is working fine with Xcode Playground.
It would have saved me a lot of time if there had been a warning when importing the framework.
I'm doing the following inside of didFinishLaunchingWithOptions:
let config = Realm.Configuration(
schemaVersion: 0,
deleteRealmIfMigrationNeeded: true
)
Realm.Configuration.defaultConfiguration = config
let realm = try! Realm()
Basically, while developing, I don't want to worry about migrations and just want to clear the database whenever the schema changes. My understanding is that's exactly what deleteRealmIfMigrationNeeded is for.
The problem is that sometimes it crashes while trying to initialize Realm with the following error:
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=5 "Directory at path '/Users/rock/Library/Developer/CoreSimulator/Devices/D626848E-14D5-47AC-8FFB-9B67D024DEF1/data/Containers/Data/Application/6F71103C-9E10-4131-BED4-D96445FABA52/Documents/default.realm' does not exist."
The default.realm file is getting removed, presumably because of deleteRealmIfMigrationNeeded, but then isn't getting recreated (as I'd expect) when initializing Realm with that last line.
Interestingly, if I manually delete default.realm.lock and then restart the app, it'll work.
Am I doing this wrong? Could this be a bug? (I'm using Realm Swift 2.4.1)
I just came across the same problem and the solution in my case was to turn off the Realm Browser if you have it open.
Cheers!
I discovered that turning off encryption when setting up the Realm will allow you to have the Realm Browser open at the same time.
What is the following error caused by? I did not make any significant changes and suddenly it started appearing:
Linking /Users/JimB/Desktop/iPhone Dev/Games4Kids/build/Debug-iphonesimulator/ETFanClub.app/Games4Kids(1 error)
duplicate symbol .objc_category_nameNSString_HTTPExtensions in (path)ViewController3 and (path)ViewController1
Command /Xcode 3.1.4/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
The symbol .objc_category_nameNSString_HTTPExtensions is duplicated, meaning the category NSString(HTTPExtensions) is declared twice ViewController3 and ViewController1.
Check that you don't have #implementation's in the headers #import-ed by both of these files, and they don't both have #implementation NSString(HTTPExtensions) simultaneously.