AutoCleaner
is a utility in Swift designed to automatically clean elements from a given collection. Based on a specified condition and frequency, it ensures your collection remains tidy and efficient.
To install AutoCleaner
into your Xcode project using SPM, add it to the dependencies value of your Package.swift:
dependencies: [
.package(url: "https://github.com/jinyongp/AutoCleaner.git", from: "1.2.0"),
]
And specify "AutoCleaner"
as a dependency of the Target in which you wish to use AutoCleaner
.
targets: [
.target(name: "YourTarget", dependencies: ["AutoCleaner"]),
]
Initialize AutoCleaner by providing a collection and a condition:
let cleaner = AutoCleaner([1, 2, 3, 4, 5]) { $0 <= 3 }
Start automatic cleaning with a specified frequency:
// count is the number of elements in the collection
cleaner.start { count in
if count > 100 {
return .seconds(30)
} else {
return .seconds(60)
}
}
cleaner.stop()
cleaner.items.forEach { print($0) }
cleaner.clean()
Get notified after every cleaning operation:
cleaner.onCleaned = { removedCount in
print("\(removedCount) elements removed.")
}
This library is released under the MIT license. See LICENSE for details.