0

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!

Alex
  • 7,432
  • 20
  • 75
  • 118

1 Answers1

2

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.

Abizern
  • 146,289
  • 39
  • 203
  • 257
  • It's reassuring to find this answer here but do you have a source? – Matt May 02 '12 at 14:28
  • @Matt A source for what? A class itself doesn't have instance variables, You need an instance of a class to have instance variables. Have a look at the Objective-C reference. – Abizern May 02 '12 at 14:40