https://github.com/bscothern/Once
A replacement for Dispatch Once in Swift
https://github.com/bscothern/Once
c carthage dispatch swift swift-package-manager swiftpm
Last synced: 8 months ago
JSON representation
A replacement for Dispatch Once in Swift
- Host: GitHub
- URL: https://github.com/bscothern/Once
- Owner: bscothern
- License: mit
- Created: 2017-10-12T04:43:53.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2021-01-07T04:38:02.000Z (about 5 years ago)
- Last Synced: 2024-08-10T14:19:01.961Z (over 1 year ago)
- Topics: c, carthage, dispatch, swift, swift-package-manager, swiftpm
- Language: Swift
- Homepage:
- Size: 43.9 KB
- Stars: 50
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Once
[](https://raw.githubusercontent.com/Carthage/Carthage/master/LICENSE.md) [](https://swift.org/package-manager) [](https://github.com/Carthage/Carthage)
A simple thread safe replacement for Dispatch Once and pthread_once for Swift.
## Swift Package Manager
Update your `Package.swift` to include the appropriate dependency below:
### Swift 5.2+
```swift
.package(name: "Once", "https://github.com/bscothern/Once.git", from: "1.4.0")
```
### Swift 4.0-5.1
```swift
.package(url: "https://github.com/bscothern/Once.git", from: "1.3.2")
```
## Carthage Usage
Include this line in your `Cartfile`:
```
github "bscothern/Once"
```
## Usage
```swift
import Once
let once = Once()
func foo() {
once.runOnce {
// Do stuff that should only execute the first time foo() is called.
}
// Do stuff
}
```