Crash subscribing to partial realm


#1

I am facing a SIGABRT and an application crash while running the following code.

This was functional until the last update (3.15.0) and server version .3.21.1

var config = SyncUser.current?.configuration(realmURL: URL(string: “MY_VALID_URL”), fullSynchronization: false, enableSSLValidation: false)
self.realm = try Realm(configuration: config!)
self.results = self.realm!.objects(MY_CUSTOM_CLASS_OBJECT.self)
self.subscription = self.results!.subscribe()

CRASH

the realm url has been checked and is valid

The content of the self.results variable has been also checked and is not nil

Thanks for advice


#2

Please, dont use force unwrap.
What happen in your case, if the SyncUser.current is nil? Where do you catch the realm errors?

With proper error handling and using guard, you can prevent these issues.


#3

Thanks for your prompt answer freeubi

you are right if the SyncUser.current is nil

I have guard statement above the code

guard let _ = SyncUser.current else {
completion(false)
return
}

But even with proper error handling i get the CRASH at the line where i create the subscription

let subscription = self.results.subscribe() <= CRASH HERE


#4

Is your realm an upgraded reference realm?


#5

yes it has been updated.


#6

I have also tried Realm.asyncOpen :

guard let current = SyncUser.current else {return}

var config = current.configuration(realmURL: URL(string: "realms://MY_REALM_URL"), fullSynchronization: false, enableSSLValidation: false)

config.objectTypes = [MY_CUSTOM_OBJECT]

Realm.asyncOpen(configuration: config) { (realm, error) in
    if let realm = realm {
        let result = realm.objects(Customer.self)
        self.subscription = result.subscribe()
    }
}

I still get the SIGABRT -> self.subscription = result.subscribe()