Skip to content

Instantly share code, notes, and snippets.

@hugithordarson
Last active July 8, 2017 18:28
Show Gist options
  • Save hugithordarson/c96966b031fe3026fccfc72107f6d420 to your computer and use it in GitHub Desktop.
Save hugithordarson/c96966b031fe3026fccfc72107f6d420 to your computer and use it in GitHub Desktop.
func decode() {
if let url = URL(string: "https://www.husvordurinn.is/Apps/WebObjects/Husvordurinn.woa/wa/GodurKodi") {
do {
let jsonData = try Data(contentsOf: url)
if let balance = try? JSONDecoder().decode(Balance.self, from: jsonData) {
for t in balance.transactions {
print( t );
}
}
} catch {
print( "TODO: Handle: Failed to retrieve data" );
}
} else {
print( "TODO: Handle: Failed to construct URL" );
}
}
struct Balance: Codable {
var balance : Double;
var unpaid: Double;
var visa: Double;
var total: Double;
var transactions : Array<Transaction>;
}
struct Transaction: Codable {
var text: String;
var date: Date;
var amount: Double;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment