Is observeValueForKeyPath
always called from the main thread?
I'm logging calls with
-(void) observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
NSLog(@"KVO: isMainThread %d", [NSThread isMainThread]);
// ...
}
and it seems to be printing 1
every time, but I was unable to find any guarantee of this in the docs. Can anyone confirm this is the case?
ArgumentException: get_persistentDataPath can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
This function must only be called from the main thread. Possible errors include NotInitializedand PlatformError. IconifyWindow(Window*) This function iconifies (minimizes) the specified window if it was previously restored. If the window is already iconified, this function does nothing.
The default priority of Main thread is 5 and for all remaining user threads priority will be inherited from parent to child. For each program, a Main thread is created by JVM (Java Virtual Machine).
This function must only be called from the main thread. Possible errors include NotInitialized. GetMonitorNameRaw(Monitor*) This function returns a human-readable name, encoded as UTF-8, of the specified monitor. The name typically reflects the make and model of the monitor and is not guaranteed to be unique among the connected monitors.
In general, no.
You receive observeValueForKeyPath:ofObject:change:context:
on the thread which changed the value. The setter method that changes the value sends the message to all observers after updating the value and before returning.
If you only call the setter on the main thread, then you will only observe the change on the main thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With