Protocol
Providable
public protocol Providable
A type that can provide concrete instances of itself.
Provide wildcard instances for generic types by conforming the base type to Providable
and
registering the type. Non-wildcard instances have precedence over wildcard instances.
extension Array: Providable {
public static func createInstance() -> Self? {
return Array()
}
}
var valueProvider = ValueProvider()
valueProvider.registerType(Array<Any>.self)
// All specializations of `Array` return an empty array
print(valueProvider.provideValue(for: Array<String>.self)) // Prints []
print(valueProvider.provideValue(for: Array<Data>.self)) // Prints []
// Register a non-wildcard instance of `Array<String>`
valueProvider.register(["A", "B"], for: Array<String>.self)
print(valueProvider.provideValue(for: Array<String>.self)) // Prints ["A", "B"]
print(valueProvider.provideValue(for: Array<Data>.self)) // Prints []
Requirements
createInstance()
static func createInstance() -> Self?
Create a concrete instance of this type, or nil
if no concrete instance is available.