Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 3 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 (about 7 years ago)
- Default Branch: main
- Last Pushed: 2021-01-07T04:38:02.000Z (almost 4 years ago)
- Last Synced: 2024-04-04T17:33:44.003Z (7 months 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
[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/Carthage/Carthage/master/LICENSE.md) [![SPM](https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat)](https://swift.org/package-manager) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](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 Oncelet once = Once()
func foo() {
once.runOnce {
// Do stuff that should only execute the first time foo() is called.
}
// Do stuff
}
```