Swiftpack.co - e-sites/Dysprosium as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by e-sites.
e-sites/Dysprosium v6.1.0
Deallocation helper for runtime objects
⭐️ 2
🕓 3 years ago
iOS
.package(url: "https://github.com/e-sites/Dysprosium.git", from: "v6.1.0")

Dysprosium

Dysprosium is part of the E-sites iOS Suite.


Deallocation helper for runtime objects.
This library is pure for debugging purposes.

forthebadge forthebadge

Travis-ci

Installation

##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"]),

Implementation

// 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)")
    }
}

Log deallocations

This way you can easily see what objects have been deallocated.

import Dysprosium

class SomeObject: DysprosiumCompatible {
    // ...
    
    deinit {
        deallocated()
    }
}

Expect deallocations

UIViewController

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()
    }
}

Related objects

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()
    }
}

Release builds

Disable Dysprosium like this:

Dysprosium.shared.isEnabled = false

GitHub

link
Stars: 2
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics