Skip to content

Instantly share code, notes, and snippets.

@IhwanID
Created August 27, 2021 22:39
Show Gist options
  • Save IhwanID/b7d07078308178a5733a29108c86a828 to your computer and use it in GitHub Desktop.
Save IhwanID/b7d07078308178a5733a29108c86a828 to your computer and use it in GitHub Desktop.
Track Memory Leaks Unit Test with XCTestCase Extension
import XCTest
extension XCTestCase{
func trackMemoryLeaks(_ instance: AnyObject, file: StaticString = #file, line: UInt = #line){
addTeardownBlock { [weak instance] in
XCTAssertNil(instance, "Instance should have been deallocated. Potential memory leak.", file: file, line: line)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment