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
/* | |
Observer Pattern | |
1. The subscriber is the "observer" object and receives updates. | |
2. The publisher is the "observable" object and sends updates. | |
3. The value is the underlying object that's changed. | |
Reference: https://howtodoinjava.com/design-patterns/behavioral/observer-design-pattern/ | |
*/ | |
import Foundation |
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
/* | |
Observer Pattern | |
1. The subscriber is the "observer" object and receives updates. `AppCoordinator` | |
2. The publisher is the "observable" object and sends updates. `LoginViewController` | |
3. The value is the underlying object that's changed. | |
*/ | |
import UIKit | |
final class AppCoordinator { | |
init() { |
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
/* | |
Memento Pattern | |
1. The `originator` is the object to be saved or restored. | |
2. The `memento` represents a stored state. | |
3. The `caretaker` requests a save from the originator and receives a memento in response. | |
The caretaker is responsible for persisting the memento and, later on, | |
providing the memento back to the originator to restore the originator’s state. | |
*/ | |
protocol Originator { |
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
/* | |
DispatchGroup | |
Create a group, register a bunch of `enter` events, `leave` when a task completes | |
and the group will automatically do code in `notify` block when all work is done | |
*/ | |
import UIKit | |
// Example for calling API | |
func callAPI(delay: Int, completion: @escaping () -> Void) { |
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
final class URLRequestBuilder { | |
private var components = URLComponents() | |
private var httpMethod: String = "GET" | |
private var headers: [String: String] = [:] | |
private var body: [String: Any]? | |
// MARK: - Lifecycle | |
init(baseUrl: String = "https://api.themoviedb.org") { | |
components = URLComponents(string: baseUrl)! |
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
protocol Strategy { | |
func execute(a: Int, b: Int) | |
} | |
class ConcreteStrategyAdd: Strategy { | |
func execute(a: Int, b: Int) { | |
print("a + b = \(a + b)") | |
} | |
} |