Skip to content

Commit

Permalink
More small readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanhimmelman authored Oct 7, 2016
1 parent b43df3d commit 3677284
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,26 @@ User(JSONString: JSONString)

#### `init(map: Map) throws`

This throwable initializer is used to map immutable properties from the given `Map`. Every immutable properties should be initialized in this initializer.
This throwable initializer is used to map immutable properties from the given `Map`. Every immutable propertie should be initialized in this initializer.

This initializer throws an error when ...
This initializer throws an error when:
- `Map` fails to get a value for the given key
- `Map` fails to transform a value using `Transform`

- ... failed to pop a value from the `Map`
- ... failed to transform a value using `Transform`

`ImmutableMappable` uses `Map.value(_:using:)` method to get values from the `Map`. This method should be used with `try` keyword because it is throwable. `Optional` properties could be easily handled using `try?`.
`ImmutableMappable` uses `Map.value(_:using:)` method to get values from the `Map`. This method should be used with the `try` keyword as it is throwable. `Optional` properties can easily be handled using `try?`.

```swift
init(map: Map) throws {
name = try map.value("name") // throws an error when fails
createdAt = try map.value("createdAt", using: DateTransform()) // throws an error when fails
name = try map.value("name") // throws an error when it fails
createdAt = try map.value("createdAt", using: DateTransform()) // throws an error when it fails
updatedAt = try? map.value("updatedAt", using: DateTransform()) // optional
posts = (try? map.value("posts")) ?? [] // optional + default value
}
```

#### `mutating func mapping(map: Map)`

This method is where the reverse transform is performed. Since immutable properties are not mapped with `<-` operator, developers have to map reverse transform manually using `>>>` operator.
This method is where the reverse transform is performed (Model to JSON). Since immutable properties can not be mapped with the `<-` operator, developers have to define the reverse transform using the `>>>` operator.

```swift
mutating func mapping(map: Map) {
Expand Down

0 comments on commit 3677284

Please sign in to comment.