Created
February 10, 2015 17:31
-
-
Save marksands/9bc811cc043dea62f105 to your computer and use it in GitHub Desktop.
Testing against strong delegates
This file contains hidden or 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 <UIkit/UIKit.h> | |
| @protocol LOLDelegate | |
| @end | |
| @interface LOLClass : NSObject <LOLDelegate> | |
| @property (nonatomic) id<LOLDelegate> strongDelegate; | |
| @end |
This file contains hidden or 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 "LOLClass.h" | |
| @implementation LOLClass | |
| @end |
This file contains hidden or 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 <XCTest/XCTest.h> | |
| #import "LOLClass.h" | |
| @interface LOLClassTests : XCTestCase | |
| @end | |
| @implementation LOLClassTests | |
| - (void)testLOLClassHasNoLeaks { | |
| __weak LOLClass *weakObject; | |
| @autoreleasepool { | |
| LOLClass *testObject = [[LOLClass alloc] init]; | |
| testObject.strongDelegate = testObject; | |
| weakObject = testObject; | |
| XCTAssertNotNil(weakObject); | |
| testObject = nil; | |
| } | |
| XCTAssertNil(weakObject); | |
| } | |
| @end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example will fail on
LOLClassTests.m:22, since the retain cycle won't allow testObject to be released.