Peter
Peter

Reputation: 75

Upgrade of Swift Realm Braking Changes, can I change a class name or how do I solve the conflict?

I'm updating Realm an iOS Swift app from 5.5.1 to 10.12.0 using Cocoa Pods.

This update have a Breaking Change public typealias User = RLMUser which conflicts with my own public final class User: Object. Refactoring to another name makes my app to crashes as assert(object.realm != nil) when reading this user class.

Is it because I've renamed my class and the realm database is expecting the old name from it's database? Or should I do some sort of merge when app start?

Or should I make my own branch changing the 'typealias User = RLMUser` in the Pod?

Upvotes: 1

Views: 289

Answers (1)

Sweeper
Sweeper

Reputation: 270980

Is it because I've renamed my class and the realm database is expecting the old name from it's database?

Yes. You can either fix this by doing a migration as described here, or you can override _realmObjectName:

class RenamedUser: Object {
    ...

    override class func _realmObjectName() -> String? {
        "User"
    }
}

This way, to Realm, RenamedUser is still called User, but to Swift, it's called RenamedUser.

Upvotes: 1

Related Questions