Is this what you look for ?
Not quite, no... I want to be able to set the value from outside, not from within one of the child classes. Here's one of the examples I tried out in a playground, which actually "crashed" with an EXC_BAD_ACCESS error. 😬
The basic idea is that it's an object that will be available to all subclasses, but that is not known at compile time and must be set at runtime. I'm trying to avoid the use of a global variable, as that's a poor solution, 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.
class foo {
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()
Topic:
Programming Languages
SubTopic:
Swift
Tags: