Updating RealmSwift pod version from 3.19.1 ~> 10?

My iOS project is currently on RealmSwift version 3.19.1, which I installed through CocoaPods when that was the most recent version. (I know, I’ve been terrible about keeping up with updates) Currently I only use the local storage parts of the RealmDB SDK, but I want to update to the latest RealmSwift version so I can start implementing sync capabilities and user authentication in my app with MongoDB.

I see there are a lot of differences between the current RealmSwift version and my 3.19.1 version, such as object variables being declared using “@Persisted” rather than “@objc dynamic”. I wanted to know if there’s a guide to migrating current object models to the new object models? Will it be fine to just update RealmSwift using the CocoaPods update function, or do I need to prepare my code prior to updating? Can object model changes like what I mentioned above be made in a realm migration?

I figure updating RealmSwift to the latest version is the first messy step towards implementing sync and a MongoDB backend, but I want to make this update in a way that won’t impact users’ saved local data when I release the update with these changes to the app store.

Great question!

We’ve been through that process with different versions and a couple of things come to mind:

First the good news is that @objc dynamic is still fully supported so you can continue to use that in your models.

It will continue to be supported “for the foreseeable future” but I would suggest any new models should be @Persisted. That being said you cannot mix them in the same model so plan accordingly.

The other good news is fundamentally, Realm works the same so the the functions and filters you’re using now will continue to work.

One thing we spent time changing is that back in the day, List of primitives like Strings and Ints were not supported - they had to consist of other realm objects. They now support primitives so that (going forward) can significantly reduce code - look for opportunities to simplify

Moving to a Sync’d app is going to take some re-thinking and there are some things to watch for:

RealmSync does not have a migration function what-so-ever so it takes a different planning when rolling out changes.

The file structure for Sync is totally different than with a local only realm - that may not affect your use case but be aware of it

You will need to implement objects with both id’s and primary keys, and retrofit your old objects if they don’t have those.

For a local only Realm, the fundamental underlying realm structure has changed as well. I am not sure if the current Realm Studio will be able to open v3 files but if it does, it will upgrade the file so make sure you have a backup before taking that step.

It’s possible you may need to get an older Realm Studio and do the upgrades as an interim step - perhaps one of the Realmers can speak to that.