The suggested code is not working. (Realm Tutorial: Step 1)



I’m working on tutorial: “Step 1 - My First Realm App”, and there’s a deprecated method and replaced it with the suggested code. But it ended up working differently. I mean it couldn’t sync with Realm Cloud.

Here’s the code I tried:
*ignore force unwrapping this time please. I used Realm Swift 3.7.4

// Old (works well)
let syncConfig: SyncConfiguration = SyncConfiguration(user: SyncUser.current!, realmURL: Constants.REALM_URL)
self.realm = try! Realm(configuration: Realm.Configuration(syncConfiguration: syncConfig, objectTypes:[Item.self]))

// New (couldn't sync with Realm Cloud)
var syncConfig: Realm.Configuration? = SyncUser.current?.configuration(realmURL: Constants.REALM_URL)
syncConfig?.objectTypes = [Item.self]
self.realm = try! Realm(configuration: syncConfig!)