Swiftpack.co -  bscothern/Once as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A replacement for Dispatch Once in Swift
.package(url: "https://github.com/bscothern/Once.git", from: "v1.3.3")


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"


import Once

let once = Once()

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


Stars: 41
Last commit: 37 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

37 weeks ago

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

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics