Hiya, Ive been trying to register a protocol that has an associatedtype as a dependency, but I have compilation error. My project has various packages and Im using your modular development design. The following is a simplified example
In PackageB:
public protocol ModuleProtocol {
associatedtype D: Codable
func show(details: D) -> any View
}
Registering the dependency with the protocol. The compiler instructs me to use any due to associatedtype
extension Container {
public var module: Factory<(any ModuleProtocol)?> { promised() }
}
In PackageA, which has PackageB as a dependency:
The class that adheres to ModuleProtocol
public final class Module: ModuleProtocol {
public typealias D = Details
public func show(details: Details) -> any View {
DetailsView(details: details)
}
}
struct Details: Codable {}
if let module = Container.shared.module() {
module.show(account: account) // compilation error here
}
I have a compilation error when trying to call the function of the instance
Member 'show' cannot be used on value of type 'any ModuleProtocol'; consider using a generic constraint instead
Perhaps my knowlegde of swift generics is letting me down here. Do you know how I can avoid this error?
Hiya, Ive been trying to register a protocol that has an associatedtype as a dependency, but I have compilation error. My project has various packages and Im using your modular development design. The following is a simplified example
In PackageB:
Registering the dependency with the protocol. The compiler instructs me to use
any
due to associatedtypeIn PackageA, which has PackageB as a dependency: The class that adheres to ModuleProtocol
Auto register the module class
Lastly, here I want to instantiate the dependency
I have a compilation error when trying to call the function of the instance
Member 'show' cannot be used on value of type 'any ModuleProtocol'; consider using a generic constraint instead
Perhaps my knowlegde of swift generics is letting me down here. Do you know how I can avoid this error?