Dysprosium is part of the E-sites iOS Suite.
Deallocation helper for runtime objects.
This library is pure for debugging purposes.
##Swift PM
package.swift dependency:
.package(url: "https://github.com/e-sites/dysprosium.git", from: "6.0.0"),
and to your application/library target, add "Dysprosium"
to your dependencies
, e.g. like this:
.target(name: "BestExampleApp", dependencies: ["Dysprosium", "DysprosiumLogger"]),
// AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// ...
Dysprosium.shared.onDealloc { objects in
print("[INFO] Deallocated objects: \(objects)")
}
Dysprosium.shared.onExpectedDeallocation { object, message in
print("[WARNING] Expected deallocation of \(object): \(message)")
}
}
This way you can easily see what objects have been deallocated.
import Dysprosium
class SomeObject: DysprosiumCompatible {
// ...
deinit {
deallocated()
}
}
Most of the time when a UIViewController
disappears it should be deallocated.
With expectDeallocation()
you can monitor if it actually is deallocated.
import Dysprosium
class SomeViewController: UIViewController, DysprosiumCompatible {
// ...
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
expectDeallocation()
}
deinit {
deallocated()
}
}
If an object gets deallocated, but you need to check that an underlying object is deallocated as well:
import Dysprosium
class SomeObject: DysprosiumCompatible {
// ...
let relatedObject: SomeObject
deinit {
relatedObject.expectDeallocation()
deallocated()
}
}
Disable Dysprosium like this:
Dysprosium.shared.isEnabled = false