Skip to content

Instantly share code, notes, and snippets.

View danielbastidasr's full-sized avatar

danielbastidasr

  • Glasgow
View GitHub Profile
@danielbastidasr
danielbastidasr / XCTestCase+MemoryLeaksTracker.swift
Last active January 19, 2024 19:19
Track memory leaks with XCTestCase
import XCTest
extension XCTestCase {
/// Given an instance, it will track at the end of every test case if it has been deallocated alerting about potential memory leak.
func trackForMemoryLeaks(_ instance: AnyObject, file: StaticString = #filePath, line: UInt = #line) {
addTeardownBlock { [weak instance] in
XCTAssertNil(instance, "Instance is not dealocated. Potential memory leak", file: file, line: line)
}
}
}