This file contains hidden or 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 AppDelegate: UIResponder, UIApplicationDelegate { | |
var backgroundSessionCompletionHandler: (() -> Void)? | |
// AppDelegate functionality. | |
} |
This file contains hidden or 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 iTunesAPIClient: URLSessionDelegate { | |
internal func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) { | |
if let appDelegate = UIApplication.shared.delegate as? AppDelegate, | |
let completionHandler = appDelegate.backgroundSessionCompletionHandler { | |
appDelegate.backgroundSessionCompletionHandler = nil | |
DispatchQueue.main.async { | |
completionHandler() | |
} | |
} |
This file contains hidden or 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
final class Download { | |
weak var delegate: DownloadDelegate? | |
var url: String? | |
var downloadTask: URLSessionDownloadTask? | |
var progress: Float = 0.0 { | |
didSet { | |
updateProgress() | |
if progress == 1 { |
This file contains hidden or 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
protocol DownloadDelegate: class { | |
// Delegate method | |
} |
This file contains hidden or 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
protocol DownloadDelegate: class { | |
func downloadProgressUpdate(for progress: Float) | |
} |
This file contains hidden or 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
final class Download { | |
weak var delegate: DownloadDelegate? | |
// Other properties | |
var progress: Float = 0.0 { | |
didSet { | |
updateProgress() | |
} |
This file contains hidden or 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 ExampleViewController: DownloadDelegate { | |
func downloadProgressUpdated(for progress: Float) { | |
DispatchQueue.main.async { | |
self.progressView.progress += progress | |
self.downloadProgressLabel.text = String(format: "%.1f%%", progress * 100) | |
} | |
} | |
} |
This file contains hidden or 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
var http = require('http'); | |
var url=require('url'); | |
var fs = require('fs'); | |
var path = require('path'); | |
var port = 3000 |
This file contains hidden or 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
var path = path.join(__dirname, 'movie.json'); |
This file contains hidden or 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
fs.readFile(path, function(error, data) { |