Skip to content

Instantly share code, notes, and snippets.

@romainmenke
Last active September 15, 2015 02:28
Show Gist options
  • Save romainmenke/7c9a28d377bdcb639c93 to your computer and use it in GitHub Desktop.
Save romainmenke/7c9a28d377bdcb639c93 to your computer and use it in GitHub Desktop.
class TicketMan {
private var ticketStack : Int = 0
private var ticketCounter : Int = 0
var ticket : Int {
get {
ticketStack += 1
ticketCounter += 1
return ticketCounter
}
}
//you set this as private and call it inside validateTicket()
func ripTicket(ticket : Int) {
ticketStack -= 1
if ticketStack == 0 {
ticketCounter = 0 //because overflows are a real thing ;)
}
}
func validateTicket(ticket: Int) -> Bool {
if ticket == ticketCounter {
return true
} else {
return false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment