Mercurial > public > simoleon
view Simoleon/Helpers/CurrencyRow.swift @ 150:6eac99e99b96
Add error handling to read json function
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Thu, 19 Aug 2021 19:12:56 +0100 |
parents | 04feeb708833 |
children | 2584fd74235a |
line wrap: on
line source
// // CurrencyRow.swift // Simoleon // // Created by Dennis Concepción Martín on 15/07/2021. // import SwiftUI struct CurrencyRow: View { var currencyPairName: String var isLocked: Bool? var body: some View { HStack { let currencyMetadata: [String: CurrencyMetadataModel] = try! read(json: "CurrencyMetadata.json") let currencies = currencyPairName.split(separator: "/") Image(currencyMetadata[String(currencies[0])]!.flag) .resizable() .aspectRatio(contentMode: .fill) .frame(width: 30, height: 30) .clipShape(Circle()) .overlay(Circle().stroke(Color(.secondaryLabel), lineWidth: 1)) Image(currencyMetadata[String(currencies[1])]!.flag) .resizable() .aspectRatio(contentMode: .fill) .frame(width: 30, height: 30) .clipShape(Circle()) .overlay(Circle().stroke(Color(.secondaryLabel), lineWidth: 1)) .offset(x: -20) .padding(.trailing, -20) Text("From \(String(currencies[0])) to \(String(currencies[1]))") .fontWeight(.semibold) .foregroundColor(Color("PlainButton")) .padding(.leading) Spacer() if isLocked ?? false { Image(systemName: "lock") .foregroundColor(.secondary) } } } } struct CurrencyRow_Previews: PreviewProvider { static var previews: some View { CurrencyRow(currencyPairName: "USD/GBP", isLocked: true) } }