Skip to content

Instantly share code, notes, and snippets.

@erkekin
Created June 15, 2022 10:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Test strong reference cycles within unit tests
public func AssertNoStrongReferenceCycle<T: AnyObject>(
file: StaticString = #file,
line: UInt = #line,
act: () throws -> T
) rethrows {
weak var system: T?
try autoreleasepool {
system = try act()
}
XCTAssertNil(system, "You've got a reference cycle in \(T.self).", file: file, line: line)
}
@erkekin
Copy link
Author

erkekin commented Jun 15, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment