Mercurial > public > lazybear
view LazyBear/Views/Home/TradingDates.swift @ 349:5ccceb527178
Implementing new internal API
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Wed, 14 Apr 2021 23:08:26 +0200 |
parents | 80bfa88c6b0f |
children | 4c90e5b18632 |
line wrap: on
line source
// // TradingDate.swift // LazyBear // // Created by Dennis Concepción Martín on 30/3/21. // import SwiftUI struct TradingDates: View { var dates: [TradingDatesModel] @Environment(\.presentationMode) var tradingDatesPresent var body: some View { NavigationView { ScrollView { VStack(spacing: 20) { ForEach(getArrayOfDates(), id: \.self) { date in TradingDatesItem(date: date) } } .padding() } .navigationTitle("Holiday dates") .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button(action: { tradingDatesPresent.wrappedValue.dismiss() }) { Image(systemName: "multiply") .imageScale(.large) } } } } } private func getArrayOfDates() -> [Date] { // Get array of the string dates let stringDates = self.dates.map { $0.date } // Convert string to date let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" // Append dates to a Date array var dates = [Date]() for stringDate in stringDates { dates.append(dateFormatter.date(from: stringDate)!) } return dates } } struct TradingDate_Previews: PreviewProvider { static var previews: some View { // Format is YYYY-MM-DD TradingDates(dates: [TradingDatesModel(date: "2021-01-01")]) } }