Mercurial > public > lazybear
comparison LazyBear/Helpers/StockSection.swift @ 465:6953d83060a4
New design
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Sat, 17 Jul 2021 17:58:57 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
464:04e430ef254a | 465:6953d83060a4 |
---|---|
1 // | |
2 // StockSection.swift | |
3 // lazybear | |
4 // | |
5 // Created by Dennis Concepción Martín on 17/07/2021. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 struct StockSection: View { | |
11 var companyQuote: CompanyQuoteModel | |
12 | |
13 var body: some View { | |
14 VStack(alignment: .leading) { | |
15 Text("Stock") | |
16 .font(.title2) | |
17 .fontWeight(.semibold) | |
18 | |
19 Text("\(companyQuote.companyName ?? "Company") is currently trading at \(companyQuote.latestPrice ?? 0, specifier: "%.2f"). That's a price change of \((companyQuote.change ?? 0.0), specifier: "%.2f") or a \((companyQuote.changePercent ?? 0)*100, specifier: "%.2f")% \(generateTendency()) since yesterday.") | |
20 } | |
21 } | |
22 | |
23 private func generateTendency() -> String { | |
24 if companyQuote.change ?? 0 >= 0 { | |
25 return "up" | |
26 } else { | |
27 return "down" | |
28 } | |
29 } | |
30 } | |
31 | |
32 struct StockSection_Previews: PreviewProvider { | |
33 static var previews: some View { | |
34 StockSection(companyQuote: CompanyQuoteModel(symbol: "AAPL", companyName: "Apple Inc", latestPrice: 120.30, changePercent: 0.03, change: 1.50)) | |
35 } | |
36 } |