Answer:
- Subscript is a shortcut way of accessing Class or Structure’s collection.
- Subscript is a feature that enables classes / structures’ to access their values in a shortcut way.
struct School {
var students: [String] = ["Paige", "Sunghee", "Seunghyun"]
subscript(index: Int) -> String {
return students[index]
}
}
let school: School = School()
print(school.students[0]) // Paige
print(school[1]) // Sunghee
Section 3, Conditional Statement
Section 10, static type vs dynamic type
Section 13, subscript
Section 15, higher order function