Created
November 27, 2016 21:25
-
-
Save nazmulkp/7eff3dc3b9000066a9ed70d9c3dd9e8e to your computer and use it in GitHub Desktop.
Building the Signals
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 fetchJSON(from url: URL) -> RACSignal { | |
print("Fetching: \(url.absoluteString)") | |
// 1 | |
return RACSignal.createSignal({(_ subscriber: RACSubscriber) -> RACDisposable in | |
// 2 | |
var dataTask = self.session.dataTask(withURL: url, completionHandler: {(_ data: Data, _ response: URLResponse, _ .error: Error) -> Void in | |
// TODO: Handle retrieved data | |
}) | |
// 3 | |
dataTask.resume() | |
// 4 | |
return RACDisposable(block: {() -> Void in | |
dataTask.cancel() | |
}) | |
}).doError({(_ error: Error) -> Void in | |
// 5 | |
print("\(.error)") | |
}) | |
} |
Author
nazmulkp
commented
Nov 27, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment