Skip to content

Instantly share code, notes, and snippets.

@dinkengraven
Last active November 21, 2015 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinkengraven/e35140bc138f56dde972 to your computer and use it in GitHub Desktop.
Save dinkengraven/e35140bc138f56dde972 to your computer and use it in GitHub Desktop.
class Breadcrumb {
var lat: Double
var long: Double
var identifier: String
var message: String
init(lat: Double, long: Double, identifier: String, message: String) {
self.lat = lat
self.long = long
self.identifier = identifier
self.message = message
}
}
// here is the call to my Rails server. It works just fine and returns the data that I would expect. Line 17
// returns the following dictionary from a nested JSON object:
// ["long": 234.232, "lat": 14.023, "updated_at": 2015-11-20T18:23:37.649Z, "identifier": Some string,
// "created_at": 2015-11-20T18:23:37.649Z, "message": Some message, "id": 1]
// The problem is that I don't understand how to do anything with the JSON data other than print it. I need to
// make a breadcrumb object with the data returned from the server.
func getBreadcrumb(id:Int) {
let breadcrumbUrl = "https://xxxxx.herokuapp.com/breadcrumbs/\(id).json"
Alamofire.request(.GET, breadcrumbUrl).validate().responseJSON { response in
switch response.result {
case .Success:
if let value = response.result.value {
let json = JSON(value)
let crumb: Dictionary<String,JSON> = json["breadcrumb"].dictionaryValue
print(crumb)
}
case .Failure(let error):
print(error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment