Skip to content

Instantly share code, notes, and snippets.

@asowers1
Last active May 5, 2016 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asowers1/e0c3d0da65d01aebbd6d1b1914155550 to your computer and use it in GitHub Desktop.
Save asowers1/e0c3d0da65d01aebbd6d1b1914155550 to your computer and use it in GitHub Desktop.
Use Completion Handlers in Xcode playgrounds
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground // we import this so we can get the main XCPlayground "page"
//create instance of current playground page
let page = XCPlayground.XCPlaygroundPage
func myCoolFunctionWithCompletion(input: String, completion: (result: String) -> Void) {
print("\(input) ... ")
completion(result: "we finished!")
}
myCoolFunctionWithCompletion("start") {
(result: String) in
print("got back: \(result)")
page.currentPage.finishExecution() // finish execution on main page
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment