Realm configuration config


Hi, if I already have an initial configuration like this:

private static let newsConfig: Realm.Configuration = {
        var config = SyncUser.current?.configuration(realmURL: Constants.NEWS_REALM_URL,
                                                     fullSynchronization: true,
                                                     enableSSLValidation: true,
                                                     urlPrefix: nil)
        return config!

How can I add schema version and migration block on it? most examples found are creating a new conf like this:

let conf = Realm.Configuration(
  schemaVersion: 1,
  deleteRealmIfMigrationNeeded: true,
  objectTypes: [Exam.self])


You’re creating a configuration object for a synchronized Realm - it doesn’t need a migration block. For the schema version, can’t you just set it before returning?


Maybe offtopic, but why you don’t need migration on a synchronized realm? How do you handle the model changes?


You can read more about it in the docs. If you have questions or something is not clear, please let us know and we’ll try to improve them :slight_smile:


So umm, what if I change a property type?
Like Double to string?


I’m adding more fields to a model. However, the way I connect now, is already working using that newsConfig config. So the question is… where to add the migration in that configuration (that’s already created)?

@objcMembers class Talk: Object {

    enum Property: String {
        case key, title, startAt, endAt, speakers, talkDescription

    dynamic var key: String = UUID().uuidString
    dynamic var title: String = ""
    dynamic var startAt: Date?
    dynamic var endAt: Date?
    dynamic var talkDescription: String = ""
    dynamic var talkIconFilename: String = "" --> Newly added
    let speakers: List<Speaker> = List<Speaker>() --> Newly added
    let feedback: List<Feedback> = List<Feedback>() --> Newly added

    override static func primaryKey() -> String? {
        return Talk.Property.key.rawValue


As for the docs, it explains You don’t need to do anything other than adding the class and associated properties before syncing:. But what if local is already synced?
The online docs also don’t mention about the most known way of migration discussed on Stackoverflow (i find it confusing)

Previously, I had this experience where Realm has error, requiring a migration when I changed let images = List<ImageItem>() to let images = List<String>()
ended up using another Realm (destructive method)