Hello. I am fairly new to SwiftUI, and I am currently making a timetable app, to help keep me organised, next academic year, so I still have a fair amount of time to complete it, before September.
I am making this app specifically for my college, and its timetabling. There are 6 periods, A-F, and every A period, you have the same lesson, every B period, etc. Parts of this project come from tutorials I have worked through, and real life examples I have looked at.
It is not at all elegant, or working, currently.
The view I am having a problem with is the so-called 'TimetableEditView'. I want a user to choose a subject from the list, for all of their periods, and then save them. These will then be used in the actual timetable.
The error I am getting, is at both lines 21 & 22.
Line 21 error: 'Cannot assign value of type 'Int' to type 'String''
Line 22 error: 'Cannot assign value of type 'String' to type 'Int''
I understand that this is because:
I want to assign the users chosen subject to a variable, that I can then use in different view.
I understand that this is quite basic compared to most questions on here, but any and all help is appreciated.
Thanks.
I am making this app specifically for my college, and its timetabling. There are 6 periods, A-F, and every A period, you have the same lesson, every B period, etc. Parts of this project come from tutorials I have worked through, and real life examples I have looked at.
It is not at all elegant, or working, currently.
The view I am having a problem with is the so-called 'TimetableEditView'. I want a user to choose a subject from the list, for all of their periods, and then save them. These will then be used in the actual timetable.
The error I am getting, is at both lines 21 & 22.
Line 21 error: 'Cannot assign value of type 'Int' to type 'String''
Line 22 error: 'Cannot assign value of type 'String' to type 'Int''
Code Block import SwiftUI struct TimetableEditView: View { var subjects = ["Free", "Maths", "English", "Geography"] @State var selectedSubjectA = 0 ... @State var retrievedSubjectA = "" ... var body: some View { Form { Section { Picker(selection: $selectedSubjectA, label: Text("A Periods").font(.body)) { ForEach(0 ..< subjects.count) { Text(self.subjects[$0]).font(.body) } } } Button(action: { UserDefaults.standard.set(self.selectedSubjectA, forKey: "SelectedSubjectA") self.retrievedSubjectA = self.selectedSubjectA self.selectedSubjectA = "" UserDefaults.standard.set(self.selectedSubjectB, forKey: "SelectedSubjectB") ... }) { Text("Save") .font(.headline) .fontWeight(.bold) .foregroundColor(.blue) } .onAppear { guard let retrievedSubjectAa = UserDefaults.standard.value(forKey: "SelectedSubjectA") else {return} self.retrievedSubjectA = retrievedSubjectAa as! String } } .navigationBarTitle("Select your subjects", displayMode: .inline) } }
I understand that this is because:
Code Block selectedSubjectA = 0
for the purposes of choosing the name from the list of subjects, and because: Code Block retrievedSubjectA = ""
which I believe means that it is a string.I want to assign the users chosen subject to a variable, that I can then use in different view.
I understand that this is quite basic compared to most questions on here, but any and all help is appreciated.
Thanks.