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
| @IBOutlet weak var progressView: UIProgressView! | |
| @IBOutlet weak var downloadProgressLabel: UILabel! |
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 defaultSession = URLSession(configuration: .default) |
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
| let url = URL(string: "http://www.google.com") |
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
| static func downloadImage(url: URL, completion: @escaping (_ image: UIImage?, _ error: Error? ) -> Void) { | |
| if let cachedImage = imageCache.object(forKey: url.absoluteString as NSString) { | |
| completion(cachedImage, nil) | |
| } else { | |
| MTAPIClient.downloadData(url: url) { data, response, error in | |
| if let error = error { | |
| completion(nil, error) | |
| } else if let data = data, let image = UIImage(data: data) { | |
| imageCache.setObject(image, forKey: url.absoluteString as NSString) |
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
| if let cachedImage = imageCache.object(forKey: url.absoluteString as NSString) { | |
| completion(cachedImage, nil) | |
| } |
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
| func downloadImage(url: URL, completion: @escaping (UIImage?) -> Void) |
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
| let imageCache = NSCache<NSString, UIImage>() |
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 MainViewController: UIViewController { | |
| @IBOutlet var mainView: MainView! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| mainView.delegate = self | |
| } | |
| } |
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 ViewController: MainViewDelegate { | |
| func searchButtonTappedWithTerm(with searchTerm: String) { | |
| print("The text in UITextField is: \(searchTerm)") | |
| } | |
| } |
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 MainView: UIView { | |
| @IBOutlet private weak var myTextfield: UITextField! | |
| @IBOutlet private weak var myButton: UIButton! | |
| weak var delegate: MainViewDelegate? | |
| override func layoutSubviews() { | |
| super.layoutSubviews() | |
| myButton.addTarget(self, action: #selector(buttonTap), for: .touchUpInside) |