-
Notifications
You must be signed in to change notification settings - Fork 923
Add KVOController for self-observing: KVOControllerForSelf #131
base: master
Are you sure you want to change the base?
Add KVOController for self-observing: KVOControllerForSelf #131
Conversation
@nlutsenko what do you think? |
There was a problem hiding this 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.
FBKVOController/FBKVOController.h
Outdated
@@ -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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
FBKVOController/FBKVOController.h
Outdated
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great!
Example:
Sure we need to unobserve manually in dealloc.