Once alternatives and similar libraries
Based on the "Utility" category.
Alternatively, view Once alternatives based on common mentions on social networks and blogs.
-
swift-algorithm-club
Algorithms and data structures in Swift, with explanations! -
SwifterSwift
A handy collection of more than 500 native Swift extensions to boost your productivity. -
libextobjc
A Cocoa library to extend the Objective-C programming language. -
InAppSettingsKit
This iOS framework allows settings to be in-app in addition to or instead of being in the Settings app. -
EKAlgorithms
EKAlgorithms contains some well known CS algorithms & data structures. -
DifferenceKit
💻 A fast and flexible O(n) difference algorithm framework for Swift collection. -
EZSwiftExtensions
:smirk: How Swift standard types and classes were supposed to work. -
Reusable
A Swift mixin for reusing views easily and in a type-safe way (UITableViewCells, UICollectionViewCells, custom UIViews, ViewControllers, Storyboards…) -
WhatsNew
Showcase new features after an app update similar to Pages, Numbers and Keynote. -
SwiftLinkPreview
It makes a preview from an URL, grabbing all the information such as title, relevant texts and images. -
BFKit-Swift
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster. -
BFKit
BFKit is a collection of useful classes and categories to develop Apps faster. -
ReadabilityKit
Preview extractor for news, articles and full-texts in Swift -
VTAcknowledgementsViewController
Acknowledgements screen displaying a list of licenses, for example from CocoaPods dependencies. -
ObjectiveKit
Swift-friendly API for a set of powerful Objective C runtime functions. -
SwiftFoundation
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux) -
AssistantKit
Easy way to detect iOS device properties, OS versions and work with screen sizes. Powered by Swift. -
DeviceGuru
DeviceGuru is a simple lib (Swift) to know the exact type of the device, e.g. iPhone 6 or iPhone 6s. Please ⭐️ this repo on the top right corner to make this repo popular. -
Retry
Haven't you wished for `try` to sometimes try a little harder? Meet `retry` -
Standard Template Protocols
Protocols for your every day iOS needs -
YAML.framework
Proper YAML support for Objective-C. Based on recommended libyaml. -
SBConstants
Generate a constants file by grabbing identifiers from storyboards in a project. -
ZamzamKit
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.
Appwrite - The open-source backend cloud platform
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Once or a related project?
README
Once([简体中文](README.zh_cn.md))
Once allows you to manage the number of executions of a task using an intuitive API.
Highlight
- [x] Safe
- [x] Efficient
- [x] Persistent
Usage
Token
Token
records the number of times the task is executed in memory, which allows the task to be executed only once during the entire lifetime of the app.
You can think of it as an alternative to dispatch_once
in OC:
static dispatch_once_t token;
dispatch_once(&token, ^{
// do something only once
});
The swift code using Token
is as follows:
let token = Token.makeStatic()
token.do {
// do something only once
}
Or, more simple:
Token.do {
// do something only once
}
You can also don't use static
:
class Manager {
let loadToken = Token.make()
func ensureLoad() {
loadToken.do {
// do something only once per manager.
}
}
}
PersistentToken
Unlike run
, do
will persist the execution history of the task (using UserDefault
).
PersistentToken
determines whether this task should be executed based on Scope
and TimesPredicate
.
Scope
Scope
represents a time range, it is an enum:
.install
: from app installation.version
: from app update.session
: from app launch.since(let since)
: fromsince(Date)
.until(let until)
: tountil(Date)
TimesPredicate
TimesPredicate
represents a range of times.
let p0 = TimesPredicate.equalTo(1)
let p1 = TimesPredicate.lessThan(1)
let p2 = TimesPredicate.moreThan(1)
let p3 = TimesPredicate.lessThanOrEqualTo(1)
let p4 = TimesPredicate.moreThanOrEqualTo(1)
do
You can use Scope
and TimesPredicate
to make any plan you want, and, yes, it is thread-safe.
let token = PersistentToken.make("showTutorial")
token.do(in: .version, if: .equalTo(0)) {
app.showTutorial()
}
// or
let later = 2.days.later
token.do(in: .until(later), if: .lessThan(5)) {
app.showTutorial()
}
done
Sometimes your asynchronous task may fail. You don't want to mark the failed task as done. You can:
let token = PersistentToken.make("showAD")
token.do(in: .install, if: .equalTo(0)) { task in
networkService.fetchAD { result in
if result.isSuccess {
showAD(result)
task.done()
}
}
}
But at this time, the judgment is no longer absolutely safe - if there are multiple threads checking the token at the same time, but it should rarely happen, 😉.
reset
You can also clear the execution history of a task:
token.reset()
It is also permissible to clear the execution history of all tasks, but at your own risk:
PersistentToken.resetAll()
Installation
CocoaPods
pod 'Once', '~> 1.0.0'
Carthage
github "luoxiu/Once" ~> 1.0.0
Swift Package Manager
dependencies: [
.package(url: "https://github.com/luoxiu/Once", .upToNextMinor(from: "1.0.0"))
]
Contributing
Encounter a bug? want more features? Feel free to open an issue or submit a pr directly!
*Note that all licence references and agreements mentioned in the Once README section above
are relevant to that project's source code only.