Skip to content

Instantly share code, notes, and snippets.

@romyilano
Forked from acchou/SupportCode.swift
Created January 23, 2018 05:47
Show Gist options
  • Select an option

  • Save romyilano/3c9ce997e2c89ad8f0ef93c479a6f1c5 to your computer and use it in GitHub Desktop.

Select an option

Save romyilano/3c9ce997e2c89ad8f0ef93c479a6f1c5 to your computer and use it in GitHub Desktop.

Revisions

  1. @acchou acchou revised this gist Mar 10, 2017. 1 changed file with 16 additions and 20 deletions.
    36 changes: 16 additions & 20 deletions SupportCode.swift
    Original file line number Diff line number Diff line change
    @@ -1,28 +1,24 @@
    import Foundation

    public func delay(delay:NSTimeInterval, closure:()->()) {
    dispatch_after(
    dispatch_time(
    DISPATCH_TIME_NOW,
    Int64(delay * Double(NSEC_PER_SEC))
    ),
    dispatch_get_main_queue(), closure)
    public func delay(_ delay: TimeInterval, closure: @escaping ()->()) {
    DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
    closure()
    }
    }

    #if NOT_IN_PLAYGROUND
    public func playgroundTimeLimit(seconds: NSTimeInterval) {

    public func playgroundTimeLimit(seconds: TimeInterval) {
    }

    #else

    import XCPlayground

    public func playgroundTimeLimit(seconds: NSTimeInterval) {
    XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
    delay(seconds) {
    XCPlaygroundPage.currentPage.finishExecution()
    }

    import PlaygroundSupport
    public func playgroundTimeLimit(seconds: TimeInterval) {
    PlaygroundPage.current.needsIndefiniteExecution = true
    delay(seconds) {
    PlaygroundPage.current.finishExecution()
    }

    #endif
    }

    #endif
  2. @acchou acchou created this gist May 24, 2016.
    28 changes: 28 additions & 0 deletions SupportCode.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    import Foundation

    public func delay(delay:NSTimeInterval, closure:()->()) {
    dispatch_after(
    dispatch_time(
    DISPATCH_TIME_NOW,
    Int64(delay * Double(NSEC_PER_SEC))
    ),
    dispatch_get_main_queue(), closure)
    }

    #if NOT_IN_PLAYGROUND

    public func playgroundTimeLimit(seconds: NSTimeInterval) {
    }

    #else

    import XCPlayground

    public func playgroundTimeLimit(seconds: NSTimeInterval) {
    XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
    delay(seconds) {
    XCPlaygroundPage.currentPage.finishExecution()
    }
    }

    #endif