-
-
Save Pasanpr/91eb6c6fabf56ead45da159cedfb0d5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Location { | |
let coordinate: Coordinate? | |
let distance: Double? | |
let countryCode: String? | |
let country: String? | |
let state: String? | |
let city: String? | |
let streetAddress: String? | |
let crossStreet: String? | |
let postalCode: String? | |
} | |
extension Location: JSONDecodable { | |
init?(JSON: [String : AnyObject]) { | |
if let lat = JSON["lat"] as? Double, lon = JSON["lng"] as? Double { | |
coordinate = Coordinate(latitude: lat, longitude: lon) | |
} else { | |
coordinate = nil | |
} | |
distance = JSON["distance"] as? Double | |
countryCode = JSON["cc"] as? String | |
country = JSON["country"] as? String | |
state = JSON["state"] as? String | |
city = JSON["city"] as? String | |
streetAddress = JSON["address"] as? String | |
crossStreet = JSON["crossStreet"] as? String | |
postalCode = JSON["postalCode"] as? String | |
} | |
} | |
struct Venue { | |
let id: String | |
let name: String | |
let location: Location? | |
let categoryName: String | |
let checkins: Int | |
} | |
extension Venue: JSONDecodable { | |
init?(JSON: [String : AnyObject]) { | |
guard let id = JSON["id"] as? String, name = JSON["name"] as? String else { | |
return nil | |
} | |
guard let categories = JSON["categories"] as? [[String: AnyObject]], let category = categories.first, let categoryName = category["shortName"] as? String else { | |
return nil | |
} | |
guard let stats = JSON["stats"] as? [String: AnyObject], let checkinsCount = stats["checkinsCount"] as? Int else { | |
return nil | |
} | |
self.id = id | |
self.name = name | |
self.categoryName = categoryName | |
self.checkins = checkinsCount | |
if let locationDict = JSON["location"] as? [String: AnyObject] { | |
self.location = Location(JSON: locationDict) | |
} else { | |
self.location = nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment