Post marked as Apple Recommended
I've heard people talking about them before, but exactly what does it refer to? I think it refers to filing something on bugreport.apple.com; am I correct?
Post not yet marked as solved
Apparently there's now stuff in Cocoa designed to protect against simultaneous pointer access, even in the same thread. Unfortunately, this has been causing problems for me with registering for KVO using the .initial observing option (which sends an observer notification as part of the registration process to make it easier to get things set up). Because the notification happens in the same frame as the setup, the context pointer is used twice in the same frame (and therefore "simultaneously"), which never used to be a problem until now. Yes, it's definitely a potential problem, as with any form of simultaneous raw pointer access, but there's no other way to use KVO contexts!So first of all, is this intended. behavior, and second, is there a way to fix this without making major changes to my code like abandoning .initial altogether? Here's an example:init() {
...
//Because of the .initial option, the registration method will call observeValue before it returns.
object.addObserver(self, forKeyPath: keyPath, options: [.initial], context: &myContextPointer)
}
func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
if context == &myContextPointer { //Crash happens here because we're accessing the pointer twice in the same frame
...
} else {
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
}
}