I'm trying to avoid the use of a global variable, as that's a poor solution,
Please do not forget, using too many class variable is as poor as, or poorer than using a global variable.
but I'm starting to wonder if Swift supports the concept of these class variables in the same way that other languages I've used do.
What sort of languages are you accustomed?
You can write something like this:
class Foo {
private static var _a: String = ""
class var a: String {
set { self._a = newValue }
get { return self._a }
}
}
class Bar: Foo {
func printit() {
print(Foo.a)
}
}
Foo.a = "abc"
let someBar = Bar()
someBar.printit()
But not sure if this is what you want.
Topic:
Programming Languages
SubTopic:
Swift
Tags: