Latest 2.0.0
Homepage https://github.com/JRG-Developer/SwiftDispatchOnce
License MIT
Platforms ios 9.0, requires ARC
Frameworks Foundation
Authors

How to Use

SwiftDispatchOnce adds an extension on DispatchQueue for performing a closure only once.

You use it as follows:

DispatchQueue.once {
  // code to execute only once
}

This automatically generates a token based on the file name, method name and line number it’s called from. If the token is found to have been used before, the closure is not executed.

Alternatively, you can provide your own token manually as follows:

DispatchQueue.once(token: "com.mydomain.uniqueName") {
  // code to execute only once
}

Installation with CocoaPods

The easiest way to add SwiftDispatchOnce to your project is using CocoaPods.

Simply add the following line to your Podfile:

pod 'SwiftDispatchOnce', '~> 1.0'

Then run pod install as you normally would.

Attribution

This library was created thanks to this StackOverflow post:

https://stackoverflow.com/questions/37886994/dispatch-once-in-swift-3

Thank you for posting, David, Tod Cunningham and VaporwareWolf.

License

SwiftDispatchOnce is available under the MIT license (see the LICENSE file for more details).

Latest podspec

{
    "name": "SwiftDispatchOnce",
    "platforms": {
        "ios": "9.0"
    },
    "version": "2.0.0",
    "summary": "SwiftDispatchOnce adds an extension on DispatchQueue for performing a closure only once",
    "homepage": "https://github.com/JRG-Developer/SwiftDispatchOnce",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Joshua Greene": "[email protected]"
    },
    "source": {
        "git": "https://github.com/JRG-Developer/SwiftDispatchOnce.git",
        "tag": "2.0.0"
    },
    "requires_arc": true,
    "frameworks": "Foundation",
    "source_files": "SwiftDispatchOnce/Library/*.{swift}",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This