Skip to content

Commit

Permalink
Initialize Document with a Dictionary/Array primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Joannis committed May 18, 2017
1 parent 40657e6 commit 979f7cd
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Sources/BSON/Interpreting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@ import Foundation

extension Document {
public init?(_ value: Primitive?) {
guard let value = value as? Document else {
return nil
if let value = value as? Document {
self = value
return
}

self = value
if let dict = value as? [String: Primitive] {
self = Document(data: dict.makeBinary())
return
}

if let array = value as? [Primitive] {
self = Document(data: array.makeBinary())
return
}

return nil
}
}

Expand Down

0 comments on commit 979f7cd

Please sign in to comment.