Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.57 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why is this code not KVO-Compliant?
  2. @interface ILViewController : NSViewController
  3.  
  4. - (ILWindowController *)windowController;
  5.  
  6. @end
  7.  
  8. @implementation ILViewController
  9.  
  10. - (NSWindowController *)windowController {
  11.     return self.view.window.windowController;
  12. }
  13.  
  14. - (void)setView:(NSView *)view {
  15.     [self willChangeValueForKey:@"windowController"];
  16.     [super setView:view];
  17.     [self didChangeValueForKey:@"windowController"];
  18. }
  19.  
  20. @end
  21.        
  22. Cannot update for observer <NSAutounbinderObservance 0x1005cf990> for the key path
  23. "windowController.mainStatus" from <ILViewController 0x1001976b0>, most likely because
  24. the value for the key "windowController" has changed without an appropriate KVO
  25. notification being sent. Check the KVO-compliance of the ILViewController class.
  26.        
  27. @interface ILViewController : NSViewController {
  28.     ILWindowController *_windowController;
  29. }
  30.  
  31. - (ILWindowController *)windowController;
  32.  
  33. @end
  34.  
  35. @implementation ILViewController
  36.  
  37. - (NSWindowController *)windowController {
  38.     return _windowController;
  39. }
  40.  
  41. - (void)setView:(NSView *)view {
  42.     [super setView:view];
  43.     _windowController = view.window.windowController;
  44. }
  45.  
  46. @end
  47.        
  48. KVO autonotifying only supports -set<Key>: methods that return void. Autonotifying
  49. will not be done for invocations of -[NSView _setWindow:].
  50. Cannot remove an observer <NSKeyValueObservance 0x102e17880> for the key path
  51. "window.windowController.mainStatus" from <NSView 0x102e13ec0>, most likely because
  52. the value for the key "window" has changed without an appropriate KVO notification
  53.  being sent. Check the KVO-compliance of the NSView class.