Reputation: 5106
I initialize realm like this at global above AppDelegate class
import RealmSwift
let realm = try! Realm()
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate{}
Then I use this following insert code like that
import Foundation
import RealmSwift
class RealmDBHelper{
func insertShop(list: OfferList){
// Insert the new list object
try! realm.write {
realm.add(list,update: true)
}
}
}
And when I change some of my realm object and run the app.The application crash at first statement at
let realm = try! Realm()
I really don't know why.But,it solve me when i remove the app from my device and install it again on same device,it worked.I will update my app at future works.But,I can let user keep crashing when they update the app from app store when i release new version with realm object changed.So,Any help with that?
Something wrong with my code?Is so,what do i need to fix because i will change realm object base on client requirement.
Upvotes: 3
Views: 4489
Reputation: 894
When you change your model objects you need to perform a 'migration' if you want to keep the previous data. Read this from Realm documentation f or details: Realm Migrations
Upvotes: 1