A simple thread safe replacement for Dispatch Once and pthread_once for Swift.
Update your Package.swift
to include the appropriate dependency below:
.package(name: "Once", "https://github.com/bscothern/Once.git", from: "1.4.0")
.package(url: "https://github.com/bscothern/Once.git", from: "1.3.2")
Include this line in your Cartfile
:
github "bscothern/Once"
import Once
let once = Once()
func foo() {
once.runOnce {
// Do stuff that should only execute the first time foo() is called.
}
// Do stuff
}