Sometimes Swift library
Sometimes is a small Swift library that makes it easy to run code… sometimes. Well, actually, just once.
Sometimes.execute(key) {
// This will run just once
}
It was highly inspired by RateLimit and with the additions that SwiftyUserDefaults provides to the NSUserDefaults
in order to remove its stringly typed nature.
Each block of code is associated to a SometimesKey
. No stringly typed API here.
let key = SometimesKey("test_key")
Then just execute it using the key.
Sometimes.execute(key) {
// This will run just once
}
Keys are persisted by default in the NSUserDefaults.standardUserDefaults()
.
A function to remove all keys is also provided.
Sometimes.reset()
I have a couple of features that I want to add but for now this is the only one that I needed for the project that I’m working on.