I’m now attempting to open a read only realm, and if it opens, use that information in my app.
When someone enters a code to join a hunt, I am trying to open a realm that uses the huntCode in the partition:
do {
try await(RealmManager.shared.openHuntRealm(huntCode: self.huntCode))
} catch {
print(error)
}
Here is the openHuntRealm function:
func openHuntRealm(huntCode: String) -> Promise<Bool> {
return Promise { resolver in
if let user = self.app.currentUser {
let partition = "hunt=" + huntCode
print(partition)
Realm.asyncOpen(configuration: user.configuration(partitionValue: partition),
callback: { result in
switch result {
case .success(let realm):
self.huntRealm = realm
self.huntToJoin = self.huntRealm.objects(Hunt.self).first
print("got here")
resolver.fulfill(true)
case .failure(let error):
print("Failed to open realm: \(error)")
resolver.fulfill(false)
}
})
} else {
resolver.fulfill(false)
}
}
}
Before implementing AwaitKit and PromiseKit, I just tried to open the Realm, it would open and print the “got here” if it found the hunt. However, that was happening too late, so I need to await the callback.
The problem is that this just hangs. It should print “got here” or “Failed to open realm: …”, but neither is happening.
Maybe this is a bug? I just can’t figure out why it wouldn’t work when the code exists or when the code is wrong.