How does addObserver:forKeyPath: work on a static class?

拜拜、爱过 提交于 2019-12-11 23:08:51

问题


I'm trying to build a static class called Logger that will upload the log files at some point, when called like [Logger uploadLogFiles].

I'm trying to add an observer to this static class like so:

[Logger addObserver:self forKeyPath:@"uploadComplete" options:NSKeyValueObservingOptionNew context:nil];

I do this just before starting an asynchronous call method for NSURLConnection. I do get a warning, saying Incompatible pointer types sending Class to parameter of type NSObject *.

However, this does not seem to work, as the observerValueForKeyPath: method never gets called.

Has anybody had any experience with adding observers to static variables in static classes?

Thanks!


回答1:


A Class has no instance variables, so there is nothing to observe.

You need to have an actual object (an instance of a class) for KVO.



来源:https://stackoverflow.com/questions/9078595/how-does-addobserverforkeypath-work-on-a-static-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!