Post

Replies

Boosts

Views

Activity

Reply to Dynamic List
Thank you. I did add a button to add new flashcards, but it adds them in default. This is the code I've written so far: struct FlashcardList: Identifiable {   var id = UUID()   var flashcard: String   var subject: String   var color: Color   }     struct NextView: View {   @ObservedObject var flashcards = Flashcards()      var body: some View {           ZStack{       Color.init(red: 0, green: 0.7, blue: 0.3, opacity: 5)       .ignoresSafeArea(.all)           NavigationView{       Section{         NavigationLink(destination:SecondView()){       Form {         ForEach(flashcards.items) { item in           VStack (alignment:.leading){             Text(item.flashcard).bold().lineLimit(2)               .foregroundColor(.blue)               .padding()             Text(item.subject).foregroundColor(.red)               .italic()             .padding()          }         }         .onDelete(perform: deleteItems)         }         }       }       .navigationBarTitle("Your Flashcards")            .navigationBarItems(trailing:     Button(action: {       let flash = FlashcardList(flashcard: "Preview...", subject: "Chemistry", color: .red)                     self.flashcards.items.append(flash)                   }     ){       Text("Add")       Image(systemName: "plus")}       )     }     }     }   func deleteItems(at offsets: IndexSet){     flashcards.items.remove(atOffsets: offsets)   } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21