Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Jan 16, 2016
1 parent d46329e commit 13a32cd
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,24 @@ public func => <T: Decodable>(lhs: AnyObject, rhs: String) throws -> T
Then there are also overloads for returning `T?`, `[T?]`, `[T?]?`, `AnyObject`, `[String: T]?` and more.

## Errors
```swift
public enum DecodingError {
public struct Info {
var path: [String]
var object: AnyObject?
var rootObject: AnyObject?
}

case MissingKey(key: String, info: Info)
case TypeMismatch(type: Any.Type, expectedType: Any.Type, info: Info)
}
```

Example:
`ErrorTypes` conforming to `DecodingError` will be caught and rethrown in the decoding process, setting metadata as the JSON object that failed decoding, the key path to it, and the root JSON object. There are currently three error-structs conforming to it:
- `TypeMismachError`
- `MissingKeyError`
- `RawRepresentableInitializationError`

```swift
let dict: NSDictionary = ["object": ["repo": ["owner": ["id" : 1, "login": "anviking"]]]]

do {
let username: String = try dict => "object" => "repo" => "owner" => "lllloogon"
let username: String = try dict => "object" => "repo" => "owner" => "name"
} catch let error {
print(error)
}

===============================
MissingKey at object.repo.owner: lllloogon in {
id = 1;
login = anviking;
}
//
// MissingKeyError at object.repo.owner: name in {
// id = 1;
// login = anviking;
// }
```

## Handling Errors
Expand Down

0 comments on commit 13a32cd

Please sign in to comment.