From fb15b3416ef39b82367441641e40f0c884a9e448 Mon Sep 17 00:00:00 2001 From: Tristan Himmelman Date: Wed, 30 Mar 2016 17:43:58 -0400 Subject: [PATCH] Added an example for keypaths to the Readme --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 57aba53..4e7df76 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,24 @@ The `responseObject` function has 3 optional parameters and a required completio ###KeyPath The `keyPath` variable is used to drill down into a JSON response and only map the data found at that `keyPath`. It supports nested values such as `data.weather` to drill down several levels in a JSON response. +``` +let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/2ee8f34d21e8febfdefb2b3a403f18a43818d70a/sample_keypath_json" +let expectation = expectationWithDescription("\(URL)") + +Alamofire.request(.GET, URL).responseObject(keyPath: "data") { (response: Response) in + expectation.fulfill() + + let weatherResponse = response.result.value + print(weatherResponse?.location) + + if let threeDayForecast = weatherResponse?.threeDayForecast { + for forecast in threeDayForecast { + print(forecast.day) + print(forecast.temperature) + } + } +} +``` #Array Responses If you have an endpoint that returns data in `Array` form you can map it with the following function: