Skip to content

Commit

Permalink
Fix Singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
antranapp committed Dec 14, 2020
1 parent 21b3df1 commit 753ee3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions LeakDetectorDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions Sources/LeakDetector/LeakDetector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
},
Expand All @@ -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<String?, Never>(nil)
public var isLeaked = CurrentValueSubject<String?, Never>(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

Expand Down

0 comments on commit 753ee3a

Please sign in to comment.