This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Profile { | |
var identifier = 0 | |
var name = "" | |
var stats = Stats() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchUserId({ id in | |
fetchUserNameFromId(id, success: { name in | |
fetchUserFollowStatusFromName(name, success: { isFollowed in | |
// The three calls in a row succeeded YAY! | |
reloadList() | |
}, failure: { error in | |
// Fetching user ID failed | |
reloadList() | |
}) | |
}, failure: { error in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchUserId() | |
.then(fetchUserNameFromId) | |
.then(fetchUserFollowStatusFromName) | |
.then(updateFollowStatus) | |
.onError(showErrorPopup) | |
.finally(reloadList) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fetchUserId() -> Promise<Int> { | |
return Promise { resolve, reject in | |
doSomethingAsync { resolve(object: userId) } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchUserId().then { id in | |
print("UserID : \(id)") | |
}.onError { e in | |
print("An error occured : \(e)") | |
}.finally { | |
print("Everything is Done :)") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchUserId() | |
.then(printUserID) | |
.onError(showErrorPopup) | |
.finally(reloadList) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Source/Promise.swift b/Source/Promise.swift | |
index f18c6ca..3186f03 100644 | |
--- a/Source/Promise.swift | |
+++ b/Source/Promise.swift | |
@@ -39,11 +39,13 @@ public class Promise<T> { | |
public init(callback: @escaping (_ resolve: @escaping ResolveCallBack, | |
_ reject: @escaping RejectCallBack) -> Void) { | |
+ print("+") | |
promiseCallBack = callback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ws | |
import then // Needed to import Promise Type | |
import Arrow // Needed to import JSON Type | |
let api = Api() // Define global api | |
struct Api { | |
// Connect to the base URL | |
private let ws = WS("http://jsonplaceholder.typicode.com") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
api.getUsers().then { json in | |
print(json) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Arrow | |
extension User: ArrowParsable { | |
mutating func deserialize(_ json: JSON) { | |
username <-- json["username"] | |
} | |
} |