Hi,
I am just a beginner in SwiftUI and am trying to create a simple app were users can individually add flashcards. In order to do that I created a list with a couple of default flashcards, however I can not find anything online which explain how to code a section were each user can add theirs from their phones.
Please let me know if you need any extra information, I am at the very beginning so not sure if I explained myself properly.
Thanks
I am just a beginner in SwiftUI and am trying to create a simple app were users can individually add flashcards. In order to do that I created a list with a couple of default flashcards, however I can not find anything online which explain how to code a section were each user can add theirs from their phones.
Please let me know if you need any extra information, I am at the very beginning so not sure if I explained myself properly.
Thanks
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)
}
}
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)
}
}