Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let dict: [Int: [String: String]] = [1546696330: ["symbol": "ETH", "amount": "1.0"],
- 1546531017: ["symbol": "ETH", "amount": "1.0"],
- 1546531031: ["symbol": "XRP", "amount": "200.0"]]
- var toKeep: [String: Int] = [:]
- dict.forEach({
- let subDict = $0.value
- if let symbol = subDict["symbol"] {
- if let currentSaved = toKeep[symbol] {
- toKeep[symbol] = currentSaved > $0.key ? $0.key : currentSaved
- } else {
- toKeep[symbol] = $0.key
- }
- }
- })
- print("ToKeep: \(toKeep)")
- var finalDict: [Int: [String: String]] = [:]
- toKeep.forEach({ finalDict[$0.value] = dict[$0.value] })
- print("finalDict: \(finalDict)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement