Created
August 5, 2013 13:40
-
-
Save jonnolen/6155980 to your computer and use it in GitHub Desktop.
Issue with weak property not getting set to nil when rac_willDeallocSignal is attached.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <ReactiveCocoa/ReactiveCocoa.h> | |
#import <SenTestingKit/SenTestingKit.h> | |
@interface rac_signal_testTests : SenTestCase | |
@end | |
@implementation rac_signal_testTests | |
-(void)test_willDeallocSignal_applied_to_strong_reference_works_as_expected_with_local_weak_reference{ | |
id val = [@{} mutableCopy]; | |
id __weak weak_val = val; | |
__block BOOL hitNext = NO; | |
[[val rac_willDeallocSignal] subscribeCompleted:^{ | |
hitNext = YES; | |
}]; | |
val = nil; | |
STAssertNil(val, nil); | |
STAssertNil(weak_val, nil); | |
STAssertTrue(hitNext, nil); | |
} | |
-(void)test_willDeallocSignal_applied_to_weak_reference_prevents_weak_reference_from_being_released{ | |
id val = [@{} mutableCopy]; | |
id __weak weak_val = val; | |
__block BOOL hitNext = NO; | |
[[weak_val rac_willDeallocSignal] subscribeCompleted:^{ | |
hitNext = YES; | |
}]; | |
//would expect, as in the test above for this to cause weak_val to be set to nil because it's | |
//referenced object has been dealloc'd due to no strong references. | |
val = nil; | |
STAssertNil(val, nil); | |
//These two asserts fail. | |
STAssertNil(weak_val, nil); | |
STAssertTrue(hitNext, nil); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment