Mercurial > public > lazybear
view LazyBear/UI/Watchlist.swift @ 178:c1aa75608c27
Implement HUD
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sun, 21 Feb 2021 17:38:23 +0100 |
parents | 8ed956c01a54 |
children | ee9f3aff962f |
line wrap: on
line source
// // Watchlist.swift // LazyBear // // Created by Dennis Concepción Martín on 19/2/21. // import SwiftUI struct Watchlist: View { @ObservedObject var hudManager: HUDManager @Environment(\.managedObjectContext) private var moc @FetchRequest(entity: Company.entity(), sortDescriptors: []) var companies: FetchedResults<Company> var body: some View { NavigationView { List { ForEach(companies, id: \.self) { company in NavigationLink(destination: CompanyView(hudManager: hudManager, name: company.name, symbol: company.symbol)) { CompanyRow(symbol: company.symbol, name: company.name) } } .onDelete(perform: removeCompany) } .navigationTitle("Watchlist 👀") .toolbar { ToolbarItem(placement: .navigationBarTrailing) { EditButton() } } } } private func removeCompany(at offsets: IndexSet) { for index in offsets { let company = companies[index] moc.delete(company) } do { try moc.save() } catch { // Error } } } struct Watchlist_Previews: PreviewProvider { static var previews: some View { Watchlist(hudManager: HUDManager()) } }