Trying to add sync to ios app but SyncUser is not found

hello everyone,

i’m new with the development of ios app , i’m working with realm database , now i want to work with realm cloud instead of using realm file , can someone help me to do that ?

i did use this :

let config = SyncUser.current?.configuration(realmURL: Constants.REALM_URL, fullSynchronization:true )
var realm = try! Realm(configuration: config)

but SyncUser is not found

thanks for any help

Akram, for starters I would go through the Task Tracker App tutorial on MongoDB Realm

https://docs.mongodb.com/realm/tutorial

I also wrote a Medium article that shows how to write a simple chat program on top of Realm for iOS.

I hope this was useful

Richard

1 Like

Akram,

Just a cursory observation, but you are opening your realm as if it were a local realm. If you are using realm cloud with a MongoDB Realm app you should probably use asyncOpen instead of the synchronous Realm open try! Realm(configuration: config). It should look something like this

    if  let user = self.app.currentUser {
        let uid = user.id
        
        // open user realm
        Realm.asyncOpen(configuration: user.configuration(partitionValue: uid),
        callback: { result in
            
            switch result {
            case .success(let realm):
                self.userRealm = realm
                
            case .failure(let error):
                fatalError("Failed to open realm: \(error)")
            }
            
        })
        
    }

Richard Krueger

1 Like