I have two lists of subjects in my app. The user can choose several subjects from the second list to add these to the first one. I now have problems with the adding process.
The cells from the second list are described by this:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("AddSubjectCell", forIndexPath: indexPath) as! AddSubjectCell
let subject = Subjects[indexPath.row] as Subject
let Semester = "\(subject.semester)"
cell.nameLabel.text = subject.name
cell.semesterLabel.text = "Semester"
cell.semesterNumberLabel.text = Semester
return cell
}
and take their data from this array:
var addSubjectsData = [ Subject(name: "A", semester: 1), Subject(name: "B", semester: 2), Subject(name: "C", semester: 3), Subject(name: "D", semester: 5), Subject(name: "E", semester: 6) ]
If the user checkmarked the cell, this part of a function is activated:
if cell.accessoryType == UITableViewCellAccessoryType.Checkmark {
selectedCellsData.append(Subject(name: selectedCellsData.last!.name, semester: selectedCellsData.last!.semester))
Hereby,
selectedCellsData.name = cell.nameLabel.text!
selectedCellsData.semester = cell.semesterNumberLabel.text!.toInt()!
The array that I am trying to append is defined as var selectedCellsData = [ Subject(name: "Initial Subject", semester: 0)]
.
On the screen of the second list is a done button. If it is pressed, this action is being activated:
@IBAction func saveSubjectDetail(segue:UIStoryboardSegue) {
subjectsData.append(Subject(name: selectedCellsData.last!.name, semester: selectedCellsData.last!.semester))
The selected cells' data should then be added to the array var subjectsData = [ Subject(name: "Investments", semester: 1), Subject(name: "Statistics", semester: 1), Subject(name: "Studium Universale", semester: 2) ]
.
Trying to run the simulator, I receive the error "[Subject] does not have a member named 'name'". Though, as it can be seen in my array, there is a member called 'name'.
Also, when I declared the class 'Subject', I also added 'name':
class Subject: NSObject {
var name: String
var semester: Int
init(name: String, semester: Int) {
self.name = name
self.semester = semester
super.init()
}
}
I would appreciate any help on how to solve this error.