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
<style id="jsbin-css"> | |
@import url(https://fonts.googleapis.com/css?family=Roboto); | |
body { | |
font-family: Roboto, sans-serif !important; | |
max-width: 650px; | |
margin: auto; | |
padding: 1em; | |
} |
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
<style id="jsbin-css"> | |
@import url(https://fonts.googleapis.com/css?family=Roboto); | |
body { | |
font-family: Roboto, sans-serif !important; | |
max-width: 650px; | |
margin: auto; | |
padding: 1em; | |
} |
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
<style id="jsbin-css"> | |
@import url(https://fonts.googleapis.com/css?family=Roboto); | |
body { | |
font-family: Roboto, sans-serif !important; | |
max-width: 650px; | |
margin: auto; | |
padding: 1em; | |
} |
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
<style id="jsbin-css"> | |
@import url(https://fonts.googleapis.com/css?family=Roboto); | |
body { | |
font-family: Roboto, sans-serif !important; | |
max-width: 650px; | |
margin: auto; | |
padding: 1em; | |
} |
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
extension NSURL : ThrowableTaskType { | |
public typealias ReturnType = (NSData, NSURLResponse) | |
public func action(completion: Result<ReturnType> -> ()) { | |
ThrowableTask<ReturnType> { | |
let session = NSURLSession(configuration: .ephemeralSessionConfiguration()) | |
let (data, response, error) = Task { callback in session.dataTaskWithURL(self, completionHandler: callback).resume()}.await() | |
guard error == nil else { throw error! } | |
return (data!, response!) |
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
class ImagePickerDemoViewController: UIViewController { | |
let imageView = UIImageView() | |
func launchImagePicker() { | |
Task { | |
do { | |
let data = try ImagePickerTask(viewController: self).await() | |
} catch Error.PhotoLibraryNotAvailable { | |
alert("Photo Library is Not Available") |
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
class ImagePickerTask : NSObject { | |
enum Error : ErrorType { | |
case PhotoLibraryNotAvailable | |
} | |
typealias CompletionHandler = [String: AnyObject]? -> () | |
var completionHandler: CompletionHandler! | |
let viewController: UIViewController |
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 load(path: String) -> ThrowableTask<NSData> { | |
return ThrowableTask { | |
switch path { | |
case "profile.png": | |
return NSData() | |
case "index.html": | |
return NSData() | |
default: | |
throw Error.NotFound | |
} |
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
let replicatedURLs = ["https://web1.swift.org", "https://web2.swift.org"] | |
let first = replicatedURLs.map(get).awaitFirst() | |
let messages = ["1", "2", "3"] | |
let all = messages.map(encrypt).awaitAll() |
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
Task { | |
print(“downloading image”) | |
var image = UIImage(data: downloadImage.await())! | |
updateImageView(image).await(.Main) | |
print(“processing image”) | |
image = processImage(image).await() | |
updateImageView(image).await(.Main) | |
print(“finished”) | |
}.async() |
NewerOlder