diff --git a/LeakDetectorDemo/AppDelegate.swift b/LeakDetectorDemo/AppDelegate.swift index d27b092..e8ed40e 100644 --- a/LeakDetectorDemo/AppDelegate.swift +++ b/LeakDetectorDemo/AppDelegate.swift @@ -17,10 +17,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { if ProcessInfo().arguments.contains("testMode") { print("The app is running in TestMode") // set to `false` so that the app doesn't crash. - LeakDetector.isEnabled = false + LeakDetector.instance.isEnabled = false } else { // set to `true` so that the app should crash when leaks occur. - LeakDetector.isEnabled = false + LeakDetector.instance.isEnabled = false } LeakDetector.instance.status @@ -31,7 +31,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ) .store(in: &cancellables) - LeakDetector.isLeaked + LeakDetector.instance.isLeaked .sink { message in if let message = message { self.showLeakAlert(message) diff --git a/Sources/LeakDetector/LeakDetector.swift b/Sources/LeakDetector/LeakDetector.swift index bdf1f4f..aa2d6c2 100644 --- a/Sources/LeakDetector/LeakDetector.swift +++ b/Sources/LeakDetector/LeakDetector.swift @@ -67,12 +67,12 @@ public class LeakDetector { let didDeallocate = (self.trackingObjects.object(forKey: objectId) == nil) let message = "<\(objectDescription): \(objectId)> has leaked. Objects are expected to be deallocated at this time: \(self.trackingObjects)" - if LeakDetector.isEnabled { + if LeakDetector.instance.isEnabled { assert(didDeallocate, message) } else if !didDeallocate { print("Leak detection is disabled. This should only be used for debugging purposes.") print("\(message)") - LeakDetector.isLeaked.send(message) + LeakDetector.instance.isLeaked.send(message) } }, receiveCompletion: { _ in @@ -105,12 +105,12 @@ public class LeakDetector { let viewDidDisappear = (!viewController.isViewLoaded && viewController.view.window == nil) let message = "\(viewController) appearance has leaked. Objects are expected to be deallocated at this time: \(self.trackingObjects)" - if LeakDetector.isEnabled { + if LeakDetector.instance.isEnabled { assert(viewDidDisappear, message) } else if !viewDidDisappear { print("Leak detection is disabled. This should only be used for debugging purposes.") print("\(message)") - LeakDetector.isLeaked.send(message) + LeakDetector.instance.isLeaked.send(message) } } }, @@ -130,16 +130,16 @@ public class LeakDetector { /// Enable leak detector. Default is false. /// /// We should enable leak detector in Debug mode only. - public static var isEnabled: Bool = false + public var isEnabled: Bool = false - public static var isLeaked = CurrentValueSubject(nil) + public var isLeaked = CurrentValueSubject(nil) #if DEBUG /// Reset the state of Leak Detector, internal for UI test only. func reset() { trackingObjects.removeAllObjects() expectationCount = 0 - LeakDetector.isLeaked.send(nil) + LeakDetector.instance.isLeaked.send(nil) } #endif