Last active
August 29, 2015 14:02
-
-
Save nielsvr/b5800e8000d8128e56b1 to your computer and use it in GitHub Desktop.
Basic class with a get/set parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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