Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-215

Array should conditionally conform to BSONValue

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.2.0
    • Component/s: None
    • Labels:

      Description

      An array should only be a BsonValue if all of its elements are BsonValue?s. Now that Swift 4.2 completes conditional conformance, we can provide better type safety around what arrays can be added to documents. 

      We currently just silently fail and convert anything that couldn't be cast to a BsonValue to nil.

      For example:

       

      let arr: [Int16] = [1, 2, 3, 4]
       var doc = Document()
       doc["a"] = arr
      print(doc) // { "a" : [ null, null, null, null ] }
      

       
      NOTE: Kaitlin Mahar brought up a good point about how we may want to instead support arrays of Codable ([Codable]).
       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              kaitlin.mahar Kaitlin Mahar
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: