문제

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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top