Last active
July 8, 2017 18:28
-
-
Save hugithordarson/c96966b031fe3026fccfc72107f6d420 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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