Skip to content

Instantly share code, notes, and snippets.

@paulw11
Created March 28, 2020 02:31
Show Gist options
  • Save paulw11/b9c4a847cd641fb56d9bff07da66be52 to your computer and use it in GitHub Desktop.
Save paulw11/b9c4a847cd641fb56d9bff07da66be52 to your computer and use it in GitHub Desktop.
let passedEarnings = [
[
"actual":"<null>",
"code" : "AUTO.US",
"date" : "2019-12-31",
"difference" : "<null>",
"estimate" : "-0.12",
"percent" : "<null>",
"report_date" : "2020-03-27"],
[
"actual" : "<null>",
"code" : "APTX.US",
"date" : "2019-12-31",
"difference" : "<null>",
"estimate" : "-0.5600000000000001",
"percent" : "<null>",
"report_date" : "2020-03-30"
],
[
"actual" : "<null>",
"code" : "APTX.AUS",
"date" : "2019-12-31",
"difference" : "<null>",
"estimate" : "-0.5600000000000001",
"percent" : "<null>",
"report_date" : "2020-03-30"
]
]
func createArray(from earnings:[[String:String]] ) -> [String:[[String:String]]] {
var arrayOfEarningsDicts = [String:[[String:String]]]()
for earning in earnings {
guard let reportDate = earning["report_date"] else {
break
}
arrayOfEarningsDicts[reportDate, default:[[String:String]]()].append(earning)
}
return arrayOfEarningsDicts
}
let array = createArray(from: passedEarnings)
for e in array.values {
for a in e {
print(a["report_date"]!)
2020-03-27
2020-03-30
2020-03-30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment