Skip to content

Instantly share code, notes, and snippets.

View chriswebb09's full-sized avatar

Christopher Webb chriswebb09

View GitHub Profile
class AppDelegate: UIResponder, UIApplicationDelegate {
var backgroundSessionCompletionHandler: (() -> Void)?
// AppDelegate functionality.
}
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()
}
}
final class Download {
weak var delegate: DownloadDelegate?
var url: String?
var downloadTask: URLSessionDownloadTask?
var progress: Float = 0.0 {
didSet {
updateProgress()
if progress == 1 {
protocol DownloadDelegate: class {
// Delegate method
}
protocol DownloadDelegate: class {
func downloadProgressUpdate(for progress: Float)
}
final class Download {
weak var delegate: DownloadDelegate?
// Other properties
var progress: Float = 0.0 {
didSet {
updateProgress()
}
extension ExampleViewController: DownloadDelegate {
func downloadProgressUpdated(for progress: Float) {
DispatchQueue.main.async {
self.progressView.progress += progress
self.downloadProgressLabel.text = String(format: "%.1f%%", progress * 100)
}
}
}
var http = require('http');
var url=require('url');
var fs = require('fs');
var path = require('path');
var port = 3000
var path = path.join(__dirname, 'movie.json');
fs.readFile(path, function(error, data) {