Skip to content

Commit

Permalink
Complete when NSUserDefaults deallocates
Browse files Browse the repository at this point in the history
  • Loading branch information
mdiep committed Dec 23, 2013
1 parent dd5d9fa commit 71c8af0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "RACScheduler.h"
#import "RACSignal+Operations.h"
#import "NSNotificationCenter+RACSupport.h"
#import "NSObject+RACDeallocating.h"
#import "NSObject+RACLifting.h"

@implementation NSUserDefaults (RACSupport)
Expand All @@ -24,7 +25,7 @@ - (RACChannelTerminal *)rac_channelTerminalForKey:(NSString *)key {
__block BOOL ignoreNextValue = NO;

@weakify(self);
[[[[[[NSNotificationCenter.defaultCenter
[[[[[[[NSNotificationCenter.defaultCenter
rac_addObserverForName:NSUserDefaultsDidChangeNotification object:self]
map:^(id _) {
@strongify(self);
Expand All @@ -40,6 +41,7 @@ - (RACChannelTerminal *)rac_channelTerminalForKey:(NSString *)key {
return YES;
}]
distinctUntilChanged]
takeUntil:self.rac_willDeallocSignal]
subscribe:channel.leadingTerminal];

[[channel.leadingTerminal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ @implementation TestObserver
expect(value).to.beNil();
});

it(@"should complete when the NSUserDefaults deallocates", ^{
defaults = [NSUserDefaults new];

RACChannelTerminal *terminal = [defaults rac_channelTerminalForKey:NSUserDefaultsRACSupportSpecStringDefault];

defaults = nil;

expect([terminal asynchronouslyWaitUntilCompleted:NULL]).to.beTruthy();
});

SpecEnd

0 comments on commit 71c8af0

Please sign in to comment.