Skip to content
Browse files

addWeakObserver: now returns an opaque handle that can be removed wit…

…h NSNotificationCenters removeObserver: method. This allows for temporary observation
  • Loading branch information...
1 parent 2681d4a commit 5cbc7be392d3a0a8af209228ba0320eef6d23f55 Aaron Sarazan committed Jan 4, 2013
Showing with 7 additions and 2 deletions.
  1. +4 −1 Source/MANotificationCenterAdditions.h
  2. +3 −1 Source/MANotificationCenterAdditions.m
View
5 Source/MANotificationCenterAdditions.h
@@ -10,6 +10,9 @@
@interface NSNotificationCenter (MAZeroingWeakRefAdditions)
-- (void)addWeakObserver: (id)observer selector: (SEL)selector name: (NSString *)name object: (id)object;
+/**
+ * Returns an opaque observation handle that can be removed with NSNotificationCenter's 'removeObserver:'.
+ */
+- (id)addWeakObserver: (id)observer selector: (SEL)selector name: (NSString *)name object: (id)object;
@end
View
4 Source/MANotificationCenterAdditions.m
@@ -12,7 +12,7 @@
@implementation NSNotificationCenter (MAZeroingWeakRefAdditions)
-- (void)addWeakObserver: (id)observer selector: (SEL)selector name: (NSString *)name object: (id)object
+- (id)addWeakObserver: (id)observer selector: (SEL)selector name: (NSString *)name object: (id)object
{
MAZeroingWeakRef *ref = [[MAZeroingWeakRef alloc] initWithTarget: observer];
@@ -29,6 +29,8 @@ - (void)addWeakObserver: (id)observer selector: (SEL)selector name: (NSString *)
[self removeObserver: noteObj];
[ref autorelease];
}];
+
+ return noteObj;
}
@end

0 comments on commit 5cbc7be

Please sign in to comment.
Something went wrong with that request. Please try again.