Group Group Group Group Group Group Group Group Group

Async Operations

Hi there,
I have a question in Chapter 8 for this code:

“var state = State.ready {
willSet {
willChangeValue(forKey: newValue.keyPath)
willChangeValue(forKey: state.keyPath)
}
didSet {
didChangeValue(forKey: oldValue.keyPath)
didChangeValue(forKey: state.keyPath)
}
}”

Excerpt From: “Concurrency by Tutorials.” iBooks.

My question is: How do we know there is a value for key “state.keyPath” and it is a Bool? I guess because there is a property like “isReady” for “Operation” class and the key is “isReady”? And that is why we need the “keyPath” property in Async Operation class to return in the format of “isReady”?

Thanks,
Mike

@gargoyle Can you please help with this when you get a chance? Thank you - much appreciated! :]

@mike If you look back a page or so you’ll see where you defined State as a String enumeration. Inside of that enum there’s the keyPath computed property which also returns a String. The paragraph right after defining the enum explains what is going on there and that you’re essentially calling the willChangeValue for something like isExecuting.