My brain is fried from heat, not even sure how to pose the question.
I have a class that has a var let's say "var isRunning: Bool = false", within it's parent another class instance with the same var where I want it to be controlled from. If I link the two, initially it's reading the var but changing later has no affect.
Sorry, I know this is probably a basic question.
Could be something like this:
protocol FromCtoB {
func updateB(val: Bool)
}
class A {
let classB = B()
let classC = C()
init() {
classC.delegate = classB
// class1.isRunning = class2.isRunning
classC.change()
print("classB.isRunning", classB.isRunning, "classC.isRunning", classC.isRunning)
}
}
class B : FromCtoB {
var isRunning: Bool = false
// Protocol implementation
func updateB(val: Bool) {
isRunning = val
}
}
class C {
var isRunning: Bool = false
var delegate: FromCtoB?
func change() {
delegate?.updateB(val: isRunning)
}
}
and
let classA = A()
yields
classB.isRunning false classC.isRunning false
if you change line 27
var isRunning: Bool = true
let classA = A()
yields
classB.isRunning true classC.isRunning true
Is it what you are looking for ?