Created
January 9, 2023 22:57
-
-
Save hmlongco/d1c43270084d8043555514aa375cc6d3 to your computer and use it in GitHub Desktop.
DeinitTracking
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
class DeinitTracker {} | |
class Test { | |
init() {} | |
#if DEBUG | |
lazy var deinitTracker: DeinitTracker? = DeinitTracker() | |
#endif | |
} | |
final class MyTests: XCTestCase { | |
func testDeinitTracking() throws { | |
var object: Test? = Test() | |
var reference: Test? = object | |
weak var tracker = object?.deinitTracker | |
object = nil | |
XCTAssertNil(object) | |
XCTAssertNotNil(reference) | |
XCTAssertNotNil(tracker) | |
reference = nil | |
XCTAssertNil(object) | |
XCTAssertNil(reference) | |
XCTAssertNil(tracker) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment