Private class members in Swift
Forums:
class Shape {
static var maxUID = 0
private var UID: Int
func getUID() -> Int {
return UID
}
init() {
Shape.maxUID += 1
UID = Shape.maxUID
}
}
class Square: Shape {
override init () {
super.init()
UID += 1 //<- Error
}
}
let square = Square()
var uid = square.getUID()
//uid is 2
uid = square.UID //<- Error
- Log in to post comments