Class type members in Swift
Forums:
class Config {
//type constant
static let maxConnections = 3
//type properties
static var host = ""
static var port = 0
//type method
static func getConnection() -> String {
return "\(host):\(port)"
}
}
Config.host = "10.0.0.1"
Config.port = 52
let connection = Config.getConnection()
//connection is "10.0.0.1:52"
- Log in to post comments