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

1.9k views Asked by At

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

There are 1 answers

2
Abizern On BEST ANSWER

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.