Skip to content

Instantly share code, notes, and snippets.

@JarvisTheAvenger
Last active October 27, 2021 05:56
Show Gist options
  • Save JarvisTheAvenger/2af8684ec453c7c276dc81f7c1236f75 to your computer and use it in GitHub Desktop.
Save JarvisTheAvenger/2af8684ec453c7c276dc81f7c1236f75 to your computer and use it in GitHub Desktop.
import Foundation
// Subscript are used to access the information from collection, sequence and a list in classes, structures and enumerations
class DaysOfWeek {
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
subscript(index: Int) -> String {
get {
return days[index]
}
set {
days[index] = newValue
}
}
}
let object = DaysOfWeek()
print(object[0]) // Monday
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment