HomeiOS Developmentios - Easy methods to cope with the return sort of RealmSwift...

ios – Easy methods to cope with the return sort of RealmSwift operate calls


When utilizing the RealmSwift package deal and calling atlas features like this:

// consumer is the RLMUser
let end result = strive await consumer.features.functionName([AnyBSON("functionArgument")])

the end result seems to be one thing like this:

doc(["status": Optional(RealmSwift.AnyBSON.int32(200)), "request": Optional(RealmSwift.AnyBSON.document(["_last": Optional(RealmSwift.AnyBSON.bool(true)), "upgradeOrConnect": Optional(RealmSwift.AnyBSON.bool(false)) ...

In my case the underlying document has around 50 key value pairs with nested documents. I am very confused as to what would be the suggested way to convert this into some Swift object or use these values without manually typing each key and using something like:

if let bson = result as? RealmSwift.AnyBSON,
   let finishReason = bson.value(forKey: "someKeyName") as? String {
    // Process 
} else {
    // Handle the case where the result is not in the expected format
}

Surely there must be some way to convert this with some simple function? I have tried

let bsonData = try BSONSerialization.data(from: bsonDocument)
let decoder = BSONDecoder()

but this throws the error “Cannot find ‘BSONSerialization’ in scope”

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments