NSObject+RACKVOWrapper.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // NSObject+RACKVOWrapper.h
  3. // ReactiveObjC
  4. //
  5. // Created by Josh Abernathy on 10/11/11.
  6. // Copyright (c) 2011 GitHub. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. @class RACDisposable;
  10. @class RACKVOTrampoline;
  11. // A private category providing a block based interface to KVO.
  12. @interface NSObject (RACKVOWrapper)
  13. // Adds the given block as the callbacks for when the key path changes.
  14. //
  15. // Unlike direct KVO observation, this handles deallocation of `weak` properties
  16. // by generating an appropriate notification. This will only occur if there is
  17. // an `@property` declaration visible in the observed class, with the `weak`
  18. // memory management attribute.
  19. //
  20. // The observation does not need to be explicitly removed. It will be removed
  21. // when the observer or the receiver deallocate.
  22. //
  23. // keyPath - The key path to observe. Must not be nil.
  24. // options - The KVO observation options.
  25. // observer - The object that requested the observation. May be nil.
  26. // block - The block called when the value at the key path changes. It is
  27. // passed the current value of the key path and the extended KVO
  28. // change dictionary including RAC-specific keys and values. Must not
  29. // be nil.
  30. //
  31. // Returns a disposable that can be used to stop the observation.
  32. - (RACDisposable *)rac_observeKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options observer:(__weak NSObject *)observer block:(void (^)(id value, NSDictionary *change, BOOL causedByDealloc, BOOL affectedOnlyLastComponent))block;
  33. @end
  34. typedef void (^RACKVOBlock)(id target, id observer, NSDictionary *change);
  35. @interface NSObject (RACUnavailableKVOWrapper)
  36. - (RACKVOTrampoline *)rac_addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options block:(RACKVOBlock)block __attribute((unavailable("Use rac_observeKeyPath:options:observer:block: instead.")));
  37. @end