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
var shouldLogTextAnalyzer = false | |
if ProcessInfo.processInfo.environment["text_analyzer_log"] == "verbose" { | |
shouldLogTextAnalyzer = true | |
} | |
if shouldLogTextAnalyzer { | |
/// Actual logger code | |
} |
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
var shouldLogTextAnalyzer = false | |
if ProcessInfo.processInfo.environment["text_analyzer_log"] == "verbose" { | |
shouldLogTextAnalyzer = true | |
} | |
if shouldLogTextAnalyzer { | |
/// Actual logger code | |
} |
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
import UIKit | |
class VerticalScrollableStackViewController: UIViewController { | |
let scrollView: UIScrollView = UIScrollView(frame: .zero) | |
let stackView: UIStackView = UIStackView(frame: .zero) | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.view.backgroundColor = .gray |
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
// Pure function | |
func sum(_ num1: Int, _ num2: int) -> Int { | |
return num1 + num2 | |
} | |
// Impure function | |
var accumulated = 0 | |
func add(_ num: Int) -> Int { | |
accumulated = num + accumulated |
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
/// Mock Subclass of ImageDownloader | |
/// Fetch API will return what you were passed while init. | |
internal class MockImageDownloader: ImageFetcher { | |
typealias MockResponse = (UIImage?, Error?) | |
/// Mocked response. Pass this as part of init and this will be the response of fetch API | |
let mockedResponse: MockResponse | |
init(url: URL, response: MockResponse) { |
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
/// Interface that fetches image from a source. | |
/// Image can be fetched from a web service or even from a local source. | |
internal protocol ImageFetcher { | |
func fetch(then completion: @escaping (UIImage?, Error?) -> Void) | |
} | |
/// ImageFetcher implementation to fetch image from web service | |
internal class ImageDownloader: ImageFetcher { | |
let url: URL | |
init(url: URL) { |
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
/// Interface that fetches image from a source. | |
/// Image can be fetched from a web service or even from a local source. | |
internal protocol ImageFetcher { | |
func fetch(then completion: @escaping (UIImage?, Error?) -> Void) | |
} | |
/// User Model | |
public class User { | |
// Stores the | |
public var name: String |
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
/// Mock Subclass of ImageDownloader | |
/// Fetch API will return what you were passed while init. | |
internal class MockImageDownloader: ImageDownloader { | |
typealias MockResponse = (UIImage?, Error?) | |
/// Mocked response. Pass this as part of init and this will be the response of fetch API | |
let mockedResponse: MockResponse | |
init(url: URL, response: MockResponse) { |
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
/// Injecting fetcher to the fetch API, so that we get control of downloading outside of the User class | |
func fetchProfileImage(fetcher: ImageDownloader, then completion: @escaping (Bool)-> Void) { | |
fetcher.fetch { (image, error) in | |
if let fetchError = error { | |
print("Failed to fetch Image with error - \(fetchError)") | |
completion(false) | |
} else if let fetchedImage = image { | |
print("Image fetched") | |
self.iProfileImage = fetchedImage | |
completion(true) |
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
import Foundation | |
import UIKit | |
internal class ImageDownloader { | |
let url: URL | |
init(url: URL) { | |
self.url = url | |
} | |
func fetch(then completion: @escaping (UIImage?, Error?) -> Void) { |
NewerOlder