Skip to content

Commit

Permalink
BSON information
Browse files Browse the repository at this point in the history
  • Loading branch information
Joannis committed Apr 8, 2017
1 parent bcd2795 commit 4d9d71f
Showing 1 changed file with 63 additions and 1 deletion.
64 changes: 63 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,72 @@ import PackageDescription

let package = Package(
name: "MyApp",
dependencies: [.Package(url: "https://github.com/OpenKitten/BSON.git", majorVersion: 4)]
dependencies: [.Package(url: "https://github.com/OpenKitten/BSON.git", majorVersion: 5)]
)
```

Create Documents naturally:

```swift
var userDocument: Document = [
"username": "Joannis",
"online": true,
"age": 20,
"pi_constant": 3.14,
"profile": [
"firstName": "Joannis",
"lastName": "Orlandos"
]
]

let favouriteNumbers: Document = [1, 3, 7, 14, 21, 24, 34]

userDocument["favouriteNumbers"] = favouriteNumbers
```

Access values in an array like you would in Swift Arrays and values in an object like a Dictionary.

```swift
let favouriteNumber = favouriteNumbers[0]
let usernameValue = userDocument["username"]
```

Extract types with simplicity:

```swift
let username = String(userDocument["username"]) // "Joannis"
let isOnline = Bool(userDocument["online"]) // true
let age = Int(userDocument["age"]) // 20
let pi = Double(userDocument["pi_constant"]) // 3.14
```

Chain subscripts easily to find results without a hassle as shown underneath using this JSON structure (assuming this is represented in BSON):

```json
{
"users": [
{
"username": "Joannis",
"profile": {
"firstName": "Joannis",
"lastName": "Orlandos"
}
},
{
"username": "Obbut",
"profile": {
"firstName": "Robbert",
"lastName": "Brandsma"
}
}
]
}
```

```swift
let obbutLastName = String(object["users"][1]["profile"]["lastName"]) // "Brandsma"
```

Check the [documentation](http://docs.openkitten.org/bson/) for more information.

### Supported Types
Expand Down

0 comments on commit 4d9d71f

Please sign in to comment.