mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-24 10:32:46 +02:00
Update RiotSwiftUI symbols to triple slash documentation style with function annotations.
This commit is contained in:
@@ -16,19 +16,18 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
Used for storing and resolving dependencies at runtime.
|
||||
*/
|
||||
/// Used for storing and resolving dependencies at runtime.
|
||||
struct DependencyContainer {
|
||||
|
||||
// Stores the dependencies with type information removed.
|
||||
private var dependencyStore: [String: Any] = [:]
|
||||
|
||||
/**
|
||||
Resolve a dependency by type.
|
||||
Given a particlar `Type` (Inferred from return type),
|
||||
generate a key and retrieve from storage.
|
||||
*/
|
||||
/// Resolve a dependency by type.
|
||||
///
|
||||
/// Given a particular `Type` (Inferred from return type),
|
||||
/// generate a key and retrieve from storage.
|
||||
///
|
||||
/// - Returns: The resolved dependency.
|
||||
func resolve<T>() -> T {
|
||||
let key = String(describing: T.self)
|
||||
guard let t = dependencyStore[key] as? T else {
|
||||
@@ -37,10 +36,10 @@ struct DependencyContainer {
|
||||
return t
|
||||
}
|
||||
|
||||
/**
|
||||
Register a dependency.
|
||||
Given a dependency, generate a key from it's `Type` and save in storage.
|
||||
*/
|
||||
/// Register a dependency.
|
||||
///
|
||||
/// Given a dependency, generate a key from it's `Type` and save in storage.
|
||||
/// - Parameter dependency: The dependency to register.
|
||||
mutating func register<T>(dependency: T) {
|
||||
let key = String(describing: T.self)
|
||||
dependencyStore[key] = dependency
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
/**
|
||||
An Environment Key for retrieving runtime dependencies to be injected into `ObservableObjects`
|
||||
that are owned by a View (i.e. `@StateObject`'s, such as ViewModels owned by the View).
|
||||
*/
|
||||
/// An Environment Key for retrieving runtime dependencies.
|
||||
///
|
||||
/// Dependencies are to be injected into `ObservableObjects`
|
||||
/// that are owned by a View (i.e. `@StateObject`'s, such as ViewModels owned by the View).
|
||||
private struct DependencyContainerKey: EnvironmentKey {
|
||||
static let defaultValue = DependencyContainer()
|
||||
}
|
||||
@@ -36,12 +36,13 @@ extension EnvironmentValues {
|
||||
@available(iOS 14.0, *)
|
||||
extension View {
|
||||
|
||||
/**
|
||||
A modifier for adding a dependency to the SwiftUI view hierarchy's dependency container.
|
||||
Important: When adding a dependency to cast it to the type in which it will be injected.
|
||||
So if adding `MockDependency` but type at injection is `Dependency` remember to cast
|
||||
to `Dependency` first.
|
||||
*/
|
||||
/// A modifier for adding a dependency to the SwiftUI view hierarchy's dependency container.
|
||||
///
|
||||
/// Important: When adding a dependency to cast it to the type in which it will be injected.
|
||||
/// So if adding `MockDependency` but type at injection is `Dependency` remember to cast
|
||||
/// to `Dependency` first.
|
||||
/// - Parameter dependency: The dependency to add.
|
||||
/// - Returns: The wrapped view that now includes the dependency.
|
||||
func addDependency<T>(_ dependency: T) -> some View {
|
||||
transformEnvironment(\.dependencies) { container in
|
||||
container.register(dependency: dependency)
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
A property wrapped used to inject from the dependency
|
||||
container on the instance to instance properties.
|
||||
E.g. ```@Inject var someClass: SomeClass```
|
||||
*/
|
||||
/// A property wrapped used to inject from the dependency container on the instance, to instance properties.
|
||||
///
|
||||
/// ```
|
||||
/// @Inject var someClass: SomeClass
|
||||
/// ```
|
||||
@propertyWrapper struct Inject<Value> {
|
||||
|
||||
static subscript<T: Injectable>(
|
||||
|
||||
@@ -16,18 +16,16 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
A protocol for classes that can be injected with a dependency container
|
||||
*/
|
||||
/// A protocol for classes that can be injected with a dependency container
|
||||
protocol Injectable: AnyObject {
|
||||
var dependencies: DependencyContainer! { get set }
|
||||
}
|
||||
|
||||
|
||||
extension Injectable {
|
||||
/**
|
||||
Used to inject the dependency container into an Injectable.
|
||||
*/
|
||||
|
||||
/// Used to inject the dependency container into an Injectable.
|
||||
/// - Parameter dependencies: The `DependencyContainer` to inject.
|
||||
func inject(dependencies: DependencyContainer) {
|
||||
self.dependencies = dependencies
|
||||
}
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
Class that can be extended and supports
|
||||
injection and the `@Inject` property wrapper.
|
||||
*/
|
||||
/// Class that can be extended that supports injection and the `@Inject` property wrapper.
|
||||
open class InjectableObject: Injectable {
|
||||
var dependencies: DependencyContainer!
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user