Skip to content

Instantly share code, notes, and snippets.

@antonio081014
Last active February 15, 2022 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonio081014/e66adef5047d1c89c81c33966f85aac4 to your computer and use it in GitHub Desktop.
Save antonio081014/e66adef5047d1c89c81c33966f85aac4 to your computer and use it in GitHub Desktop.
import XCTest
extension XCTestCase {
func trackForMemoryLeaks(_ 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)
}
}
}
// Here is how to call this function.
trackForMemoryLeaks(instance, file: file, line: line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment