Mercurial > public > lazybear
comparison LazyBear/Views/Home/TradingDates.swift @ 336:6f904b166564
Implementing TradingDaysView
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Wed, 31 Mar 2021 20:42:44 +0200 |
parents | 41c9252fc76c |
children | 31f2838b2de7 |
comparison
equal
deleted
inserted
replaced
335:2dad5828ccf6 | 336:6f904b166564 |
---|---|
6 // | 6 // |
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct TradingDates: View { | 10 struct TradingDates: View { |
11 var stringDates: [TradingDatesModel] | |
11 | 12 |
12 var body: some View { | 13 var body: some View { |
13 NavigationView { | 14 NavigationView { |
14 ScrollView { | 15 ScrollView { |
15 VStack(spacing: 30) { | 16 VStack(spacing: 30) { |
16 ForEach((1..<10)) { index in | 17 ForEach(getArrayOfDates(), id: \.self) { date in |
17 TradingDatesItem() | 18 TradingDatesItem(date: date) |
18 } | 19 } |
19 } | 20 } |
20 .padding() | 21 .padding() |
21 } | 22 } |
22 .navigationTitle("Trading dates") | 23 .navigationTitle("Holiday dates") |
23 } | 24 } |
25 } | |
26 | |
27 | |
28 private func getArrayOfDates() -> [Date] { | |
29 // Get array of the string dates | |
30 let stringDates = self.stringDates.map { $0.date } | |
31 | |
32 // Convert string to date | |
33 let dateFormatter = DateFormatter() | |
34 dateFormatter.dateFormat = "yyyy-MM-dd" | |
35 | |
36 // Append dates to a Date array | |
37 var dates = [Date]() | |
38 for stringDate in stringDates { | |
39 dates.append(dateFormatter.date(from: stringDate)!) | |
40 } | |
41 | |
42 return dates | |
24 } | 43 } |
25 } | 44 } |
26 | 45 |
27 struct TradingDate_Previews: PreviewProvider { | 46 struct TradingDate_Previews: PreviewProvider { |
28 static var previews: some View { | 47 static var previews: some View { |
29 TradingDates() | 48 // Format is YYY-MM-DD |
49 TradingDates(stringDates: [TradingDatesModel(date: "2020-04-01")]) | |
30 } | 50 } |
31 } | 51 } |