ios – Realm + SwiftUI — replace Schema Model

0
3


I’m making an attempt to replace the Schema model, in order that I can change the schema additively (simply add one property with out affecting current information).

I ran the next code on load of my dwelling display view:

var configCheck = Realm.Configuration();
do {
    let fileUrlIs = attempt schemaVersionAtURL(configCheck.fileURL!)
    print("schema model (fileUrlIs)")
} catch  {
    print(error)
}

The schema model was 0.

I then added this to the onload operate:

 var config = Realm.Configuration.defaultConfiguration
config.schemaVersion = 2
let realm = attempt! Realm(configuration: config)
        
configCheck = Realm.Configuration();
do {
    let fileUrlIs = attempt schemaVersionAtURL(configCheck.fileURL!)
    print("schema model (fileUrlIs)")
} catch  {
    print(error)
}

When I attempt to write to the database, I get this error:

RealmSwift/SwiftUI.swift:483: Deadly error: ‘attempt!’ expression unexpectedly raised an error: Error Area=io.realm Code=1 “Supplied schema model 0 is lower than final set model 2.” UserInfo={NSLocalizedDescription=Supplied schema model 0 is lower than final set model 2., Error Code=1}

2023-01-23 14:33:30.862303+0400 AppName[87285:5267261] RealmSwift/SwiftUI.swift:483: Deadly error: ‘attempt!’ expression unexpectedly raised an error: Error Area=io.realm Code=1 “Supplied schema model 0 is lower than final set model 2.” UserInfo={NSLocalizedDescription=Supplied schema model 0 is lower than final set model 2., Error Code=1}

How do I do that correctly? I am undecided what the error means, as I believed I had up to date the schema model (working the unique code now says schema model 2).

LEAVE A REPLY

Please enter your comment!
Please enter your name here