Skip to content

Instantly share code, notes, and snippets.

@nielsvr
Last active August 29, 2015 14:02
Show Gist options
  • Save nielsvr/b5800e8000d8128e56b1 to your computer and use it in GitHub Desktop.
Save nielsvr/b5800e8000d8128e56b1 to your computer and use it in GitHub Desktop.
Basic class with a get/set parameter
import Cocoa
class thisOffice {
var currentUsers: Int
var totalSpaces : Int
init(currentUsers: Int, totalSpaces: Int) {
self.currentUsers = currentUsers
self.totalSpaces = totalSpaces
}
var freeSpaces: Int {
get {
return totalSpaces - currentUsers
}
set {
self.currentUsers = totalSpaces - newValue
}
}
}
var currentOffice = thisOffice(currentUsers: 4, totalSpaces: 6);
currentOffice.freeSpaces
currentOffice.freeSpaces = 1
currentOffice.currentUsers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment