// //  CardsView.swift //  Lunch Card (iOS) // //  Created by Joshua Srery on 12/17/20. //  Additional code by OOPer on Apple Developer Forums // import SwiftUI struct Card: Identifiable {     let id = UUID()     let title: String } struct CardsView: View {     @StateObject var cardsInfo = CardsInfo()     @StateObject var sheetInfo = SheetInfo()     @State private var editMode = EditMode.inactive     @State var presentMode = false          var body: some View {         NavigationView {             List {                 ForEach(cardsInfo.cards) { card in                     NavigationLink(destination: CardFullView(cname: card.cname, name: card.name, id: card.id, code: card.code, color: card.color)) {                         CardRow(cname: card.cname, name: card.name, id: card.id, code: card.code, color: card.color)                                              }                 }                 .onDelete(perform: onDelete)                 .onMove(perform: onMove)             }.listStyle(PlainListStyle())             .navigationTitle("Cards")             .toolbar {                 ToolbarItem(placement: .navigationBarLeading) {                     EditButton()                 }                 ToolbarItem(placement: .navigationBarLeading) {                     NavigationLink(                         destination: Text("Instructions"),                         label: {                             Image(systemName: "info.circle")                         })                 }                 ToolbarItem(placement: .navigationBarTrailing) {                     Button(action: {                         self.sheetInfo.showSheetView.toggle()                     }) {                         Image(systemName: "plus")                     }                 }             }             .environment(\.editMode, $editMode)             .sheet(isPresented: $sheetInfo.showSheetView) {                 AddView(cardsInfo: cardsInfo, sheetInfo: sheetInfo)             }             .onAppear {                 cardsInfo.loadCards()             }         }     }          private func onDelete(offsets: IndexSet) {         self.presentMode.toggle()         cardsInfo.cards.remove(atOffsets: offsets)         cardsInfo.saveCards()     }          private func onMove(source: IndexSet, destination: Int) {         cardsInfo.cards.move(fromOffsets: source, toOffset: destination)         cardsInfo.saveCards()     } }