Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
swieland committed Nov 9, 2017
1 parent 0613f34 commit e9c5dd2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Struct to make simple `[String: Any]` dictionaries conform to `Codable`.

### Decoding

```
```swift
let data1: Data = try! Data(contentsOf: Bundle.main.url(forResource: "test", withExtension: "json")!)
let dict = try? JSONDecoder().decode(CodableDictionary.self, from: data)
let name = dict?["name"]
Expand All @@ -19,15 +19,15 @@ let name = dict?["name"]

`CodableDictionary` can be initialised with [String: Any].

```
```swift
let dict = CodableDictionary(value: ["foor": 233, "nested": ["n1": "hallo", "n2": "welt", "nested": ["n1": "hallo", "n2": "welt"]]])
let encodedData: Data = try! JSONEncoder().encode(dict)
let jsonString = String(data: encodedData, encoding: .utf8)
```

Encoding of custom models is also supported. So you can simply wrap models into an dictionary.

```
```swift
struct User: Codable {
let name: String
}
Expand All @@ -50,7 +50,7 @@ let jsonString = String(data: encodedData, encoding: .utf8)
Since `CodableDictionary` has to know the type of model which has to be decoded/encoded, `Any` has to be one of the following types:

| supported types of Any |
| ------------- | ----------------- |
| ------------- |
| String, [String] |
| Bool, [Bool] |
| Int, [Int] |
Expand Down

0 comments on commit e9c5dd2

Please sign in to comment.