Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Add KVOController for self-observing: KVOControllerForSelf #131

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

k06a
Copy link

@k06a k06a commented Jul 6, 2017

Example:

[self.KVOControllerForSelf observe:self keyPath:FBKVOKeyPath(self.viewModel.name) options:options block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *, id> *_Nonnull change){
    // ...
}];

Sure we need to unobserve manually in dealloc.

@k06a
Copy link
Author

k06a commented Jul 19, 2017

@nlutsenko what do you think?

Copy link
Contributor

@nlutsenko nlutsenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting per comments inline.
It is important not to break the API, and there is a nice way to achieve this.

@@ -76,7 +82,7 @@ typedef void (^FBKVONotificationBlock)(id _Nullable observer, id object, NSDicti
@return The initialized KVO controller instance.
@discussion Use retainObserved = NO when a strong reference between controller and observee would create a retain loop. When not retaining observees, special care must be taken to remove observation info prior to observee dealloc.
*/
- (instancetype)initWithObserver:(nullable id)observer retainObserved:(BOOL)retainObserved NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithObserver:(nullable id)observer storeType:(FBKVOControllerObjectStoreType)storeType NS_DESIGNATED_INITIALIZER;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is quite important not to change the public API, since there might be folks still using it.
How about we deprecate the existing method, but still make it work and add this one as a new method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -52,6 +52,12 @@ extern NSString *const FBKVONotificationKeyPathKey;
*/
typedef void (^FBKVONotificationBlock)(id _Nullable observer, id object, NSDictionary<NSKeyValueChangeKey, id> *change);

typedef NS_ENUM(NSUInteger, FBKVOControllerObjectStoreType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add documentation for the ENUM and all constants here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Use this version when a strong reference between controller and observed object would create a retain cycle.
When not retaining observed objects, special care must be taken to remove observation info prior to deallocation of the observed object.
*/
@property (nonatomic, strong) FBKVOController *KVOControllerForSelf;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants