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 Combine | |
// Helper function to print the description of the example before running it. | |
public func example(of description: String, action: () -> Void) { | |
print("\n——— Example of:", description, "———") | |
action() | |
} | |
// Simple struct to represent a coordinate with x and y values. |
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 Combine | |
import SwiftUI | |
class CustomSubscriber: Subscriber { | |
typealias Input = Int | |
typealias Failure = Never | |
func receive(subscription: Subscription) { | |
subscription.request(.unlimited) // Request unlimited values. | |
} |
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
/* | |
MARK: GENERICS | |
enables you to write flexible, reusable functions and types that can work with any type | |
*/ | |
// MARK: Generic Functions | |
// MARK: T is a Type Parameter (T, U, V) | |
// MARK: solution without Generics | |
// with inout you can change a parameter value, becase by default they are constants |
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 SwiftUI | |
/// 1. Create the environment key to hold the custom caption background color. | |
private struct CaptionColorKey: EnvironmentKey { | |
static let defaultValue = Color(.secondarySystemBackground) | |
} | |
/// 2. Extend the environment to provide access to the custom caption background color. | |
extension EnvironmentValues { | |
var captionBackgroundColor: Color { |
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 | |
/// A property wrapper that provides type-safe access to user defaults. | |
@propertyWrapper | |
struct UserDefault<Value> { | |
// MARK: Properties | |
/// The wrapped value representing the user default. | |
var wrappedValue: Value { | |
get { |
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 Combine | |
import Foundation | |
// As any Publisher | |
func fetchMovies() -> AnyPublisher<MovieResponse, Error> { | |
let url = URL(string: "https://api.themoviedb.org/3/movie/upcoming?api_key=123")! | |
return URLSession | |
.shared | |
.dataTaskPublisher(for: 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
import Combine | |
import Foundation | |
/* | |
+----------------+ +------------------------+ +-------------------+ | |
| View | ----> | ViewModel | ----> | Interactor | | |
| | | | | | | |
| ViewEvents | <---- | ViewState DomainMap | <---- | DomainState | | |
+----------------+ +------------------------+ +-------------------+ | |
^ | |
NewerOlder