Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //: Playground - noun: a place where people can play
- import UIKit
- import XCPlayground
- import PlaygroundSupport
- PlaygroundPage.current.needsIndefiniteExecution = true
- var movie: String?;
- var actor1: String?;
- var actor2: String?;
- var db = ["a1": "Abe", "a2": "Betty", "m1": "Ben Hur"]
- func printEvent() {
- print( actor1 ?? "unknown", ":",
- movie ?? "unknown",":",
- actor2 ?? "unknown")
- }
- func apiCall(url: String, completion: @escaping (_ result: String) -> Void) {
- print("get apiCalled with url: " + url);
- DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {
- // Put your code which should be executed with a delay here
- if let result = db[url] {
- completion(result);
- }
- else {
- completion("error");
- }
- })
- }
- func setActor1(result: String) {
- actor1 = result;
- apiCall(url: "m1", completion: setMovie)
- }
- func setMovie(result: String) {
- movie = result;
- apiCall(url: "a2", completion: setActor2)
- }
- func setActor2(result: String) {
- actor2 = result;
- printEvent()
- PlaygroundPage.current.finishExecution()
- }
- apiCall(url: "a1", completion: setActor1)
- print("After Setup");
- printEvent()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement