• Ask a Question
  • Create a Poll
    Ask a Question
    More answer You can create 5 answer(s).
      Ask a Poll

      "No exact matches in call to initializer" using OpenKitten/BSON package

      I am trying to use the OpenKitten/BSON Swift package on a new project, and I’m unable to access any values on a created Document while following the README instructions.

      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 (...) 

      I’m still learning Swift, and it seems this library implements a lot of advanced concepts that I’m still not sure how to properly unwrap.

      What am I doing wrong here?

      1 Answers

      It seems the REAMDE was outdated and with inaccurate information.

      One way to properly decode a Document involves using BSONDecoder().decode(type, from), such as this:

      struct Message: Codable {   let type: String; }  let data: Document = [ "type": "createSession" ]  do {   let message = try BSONDecoder().decode(Message.self, from: Document(data: data))   print(message.type);   // This should work } catch {   print("error is \(error.localizedDescription)") } 
      Answered by Hueyjeanvickie on August 31, 2020..