orlandos-nl / BSON

Native Swift library for BSON (http://bsonspec.org)
https://orlandos.nl/docs/mongokitten/articles/bson
MIT License
109 stars 35 forks source link

“No exact matches in call to initializer” when reading data #64

Closed WesSouza closed 4 years ago

WesSouza commented 4 years ago

I am trying to use this package on a new project, and I'm unable to access any values on a created Document while following the same method as the README states.

The compiler is unable to use the value:

let data: Document = [ "type": "createSession" ]
let type = String(data["type"])
//         ^ No exact matches in call to initializer 
print(type);

If I add a breakpoint and observe the value using lldb, it does have a debugger output, so the data exists:

(lldb) vo data
(BSON.Document) data = ▿ ["type": "createSession"]
  ▿ storage : ByteBuffer (...)

Did this stop working on newer versions of Swift?

Joannis commented 4 years ago

Hello @WesSouza, which version of BSON are you using? The readme still describes the old 5.x version of BSON. The latest version of BSON which is used in MongoDB is 7.x.

WesSouza commented 4 years ago

@Joannis I have installed this using Swift Package Manager, so I'm using version 7.0.23.

Is there a place I can find references on how to encode and decode data? I'm using this for a personal project to decode binary WebSocket messages.

Would also be super happy to contribute to an update to README if I can find more data about it.

Joannis commented 4 years ago

If you're looking for Codable, be sure to use BSONEncoder and BSONDecoder.

Joannis commented 4 years ago

I've just updated the docs, but feel free to make a PR for any info you might find helpful.