Skip to content

Commit 0ed8033

Browse files
committed
Merge pull request #9 from narirou/patch-1
Add syntax highlighting to Readme.md
2 parents 99fd634 + 4c47614 commit 0ed8033

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ This project uses a variety of Swift features including *Protocol Extensions* an
4242
`JSONDecodable` allows you to generate structs from `NSDictionary` coming in from a network request for example.
4343

4444
We'll use the following models in this example:
45-
```
45+
```swift
4646
struct User {
4747
let id: Int
4848
let name: String
@@ -61,7 +61,7 @@ struct Company {
6161

6262
Simply add conformance to `JSONEncodable` (or to `JSONCodable`):
6363

64-
```
64+
```swift
6565
extension User: JSONEncodable {
6666
func toJSON() throws -> AnyObject {
6767
var result: [String: AnyObject] = [:]
@@ -80,13 +80,13 @@ extension Company: JSONEncodable {}
8080
The default implementation of `func toJSON()` inspects the properties of your type using reflection (see `Company`.) If you need a different mapping, you can provide your own implementation (see `User`.)
8181

8282
Instantiate your struct, then use the `func toJSON()` method to obtain a equivalent form suitable for use with `NSJSONSerialization`:
83-
```
83+
```swift
8484
let dict = try user.toJSON()
8585
print("dict: \(dict)")
8686
```
8787

8888
Result:
89-
```
89+
```swift
9090
[full_name: John Appleseed, id: 24, email: john@appleseed.com, company: {
9191
address = "1 Infinite Loop, Cupertino, CA";
9292
name = Apple;
@@ -109,7 +109,7 @@ Result:
109109
##Using JSONDecodable
110110

111111
Simply add conformance to `JSONDecodable` (or to `JSONCodable`):
112-
```
112+
```swift
113113
extension User: JSONDecodable {
114114
init?(JSONDictionary: [String:AnyObject]) {
115115
do {
@@ -143,13 +143,13 @@ extension Company: JSONDecodable {
143143
Simply provide the implementations for `init?(JSONDictionary: [String:AnyObject])`.
144144
As before, you can use this to configure the mapping between keys in the Dictionary to properties in your structs and classes.
145145

146-
```
146+
```swift
147147
let user = User(JSONDictionary: JSON)
148148
print("\(user)")
149149
```
150150

151151
Result:
152-
```
152+
```swift
153153
User(
154154
id: 24,
155155
name: "John Appleseed",
@@ -184,7 +184,7 @@ The convenience initializer `init?(JSONString: String)` is provided on `JSONDeco
184184

185185
To transform values, create an instance of `JSONTransformer`:
186186

187-
```
187+
```swift
188188
let JSONTransformerStringToNSURL = JSONTransformer<String, NSURL>(
189189
decoding: {NSURL(string: $0)},
190190
encoding: {$0.absoluteString})
@@ -194,7 +194,7 @@ A `JSONTransformer` converts between 2 types, in this case, `String` and `NSURL`
194194

195195
Next, use the overloaded versions of `func encode()` and `func decode()` to supply the transformer:
196196

197-
```
197+
```swift
198198
struct User {
199199
...
200200
var website: NSURL?

0 commit comments

Comments
 (0)