Mercurial > public > lazybear
view LazyBear/UI/Watchlist.swift @ 176:8ed956c01a54
Update UI
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sat, 20 Feb 2021 19:29:31 +0100 |
parents | 125d268db489 |
children | c1aa75608c27 |
line wrap: on
line source
// // Watchlist.swift // LazyBear // // Created by Dennis Concepción Martín on 19/2/21. // import SwiftUI struct Watchlist: View { @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(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) } try? moc.save() } } struct Watchlist_Previews: PreviewProvider { static var previews: some View { Watchlist() } }