title: How to set the default SyncConfiguration for Realm, so I can get it in multiple ViewControlllers without redundant code?
body: <p>According to the:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/31590717/proper-realm-usage-patterns-best-practices">Proper Realm usage patterns/best practices</a></li>
  <li><a href="https://stackoverflow.com/questions/41179789/what-is-the-best-practice-or-design-pattern-to-maintain-sync-activity-across-mul">What is the best practice or design pattern to maintain sync activity across multiple views</a></li>
  <li><a href="https://stackoverflow.com/questions/36145771/design-pattern-for-realm-database-swift-3-1-singleton">Design Pattern for Realm Database Swift 3.1 - Singleton</a></li>
  </ul>
  
  <p>my approach is like:</p>
  
  <blockquote>
    <p>AppDelegate.swift</p>
  </blockquote>
  
  <pre><code>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool {
      // Override point for customization after application launch.
      DispatchQueue.main.async {
          let username = "test@test.com"
          let password = "Test123"
          let serverUrl = URL(string: "http://test.com:9080")
          let realmUrl = URL(string: "realm://test.com:9080/~/realmtest")
  
          if let user = SyncUser.current {
              Realm.Configuration.defaultConfiguration.syncConfiguration = SyncConfiguration(user: user, realmURL: realmUrl!)
          } else {
              SyncUser.logIn(with: .usernamePassword(username: username, password: password, register: false), server: serverUrl!, onCompletion: { (user, error) in
                  guard let user = user else {
                      print("Error: \(String(describing: error?.localizedDescription))")
                      return
                  }
                  Realm.Configuration.defaultConfiguration.syncConfiguration = SyncConfiguration(user: user, realmURL: realmUrl!)
              })
          }
      }
  
      return true
  }
  </code></pre>
  
  <blockquote>
    <p>ViewController.swift</p>
  </blockquote>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
      print("SyncConfiguration: \(String(describing: Realm.Configuration.defaultConfiguration.syncConfiguration))")
      self.realm = try! Realm()
  }
  </code></pre>
  
  <p>When I open app for the first time nothing happens but when I open app the second time, Realm works fine.</p>
  
  <p>Whenever I open app, the printed <code>SyncConfiguration</code> is <code>nil</code>. No errors!</p>
  
  <p>Searched here and there and can't find an answer...</p>