Swiftpack.co - Package - bscothern/Once
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

Once

GitHub license SPM Carthage compatible

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+

.package(name: "Once", "https://github.com/bscothern/Once.git", from: "1.4.0")

Swift 4.0-5.1

.package(url: "https://github.com/bscothern/Once.git", from: "1.3.2")

Carthage Usage

Include this line in your Cartfile:

github "bscothern/Once"

Usage

import Once

let once = Once()

func foo() {
    once.runOnce {
        // Do stuff that should only execute the first time foo() is called.
    }
    // Do stuff
}

Github

link
Stars: 36

Releases

v1.3.3 - 2021-01-07T04:38:02

Cleaned up some formatting. Cleaned up pointer operations. Added a concurrent operations test.

v1.3.2 - 2019-11-15T06:46:53

Fixed rare potential for memory corruption because of how Swift handles memory. See the Swift Forums and read the thread stating with this post: https://forums.swift.org/t/atomic-property-wrapper-for-standard-library/30468/15

v1.3.1 - 2018-10-06T20:38:14

Swift 4.2 is now used for Xcode projects.

The latest iOS, macOS, tvOS, and watchOS are targeted.

- 2018-05-09T20:56:10

Linux Support

- 2018-04-13T03:24:34

Simplified use of C module, includes, etc.

v1.1.0 - 2018-03-22T21:39:03

Added SPM Support

- 2018-01-25T06:26:46