BaseTransformer
open class BaseTransformer<T> : ConfigurationTransforming
BaseTransformer
it’s a helper class which can be used with ConfigurationTransformer
to tranform a value to a typed object using any transformer method. The method can be a static func, a closure or an initializer.
*There are several default transformers in the SDK which can be used as
transformer
transformToURL
transformToValue
: generic method for any base value type; can be usedOAuth2AuthenticationParameters.init(discoveryServiceConfig:)
SAMLAuthenticationParameters.init(discoveryServiceConfig:)
Example structure: “`Swift let configuration : [String: Any] = [ "someExampleURL”: “https://www.sap.com”, “someString” : “An arbitrary string”, “settingsExchange” : [ “passwordPolicy”: [ “somePolicyProperty”:“someValue”, “somePolicyProperty2”:“someValue2”, ], “logSettings”: [ “someLogProperty”:“someValue”, “someLogProperty2”:“someValue2”, ] ] ]
// The example transformationMap for the structure
let sampleTransformationMap : [String: ConfigurationTransforming] = [
“someExampleURL” : BaseTransformer(targetKey: .requiredURL, transformer: transformToURL),
“someString” : BaseTransformer
-
initializes a transformer which calls the
transformer
passed in the parameter to tranform the data to another data and returns it associating it with thetargetKey
parameterDeclaration
Swift
public init(targetKey: OnboardingInfoKey, transformer: @escaping (_ config: Any) throws -> T = transformToValue)
Parameters
targetKey
transformed data will be associated with this key in the returning dictionary
transformer
closure, func or initializer which can transform the input data of the
transform(config:)
method to another data -
Transform the input data using the associated transformer to another data and associates the result with the key associated with this instance
Throws
errors thrown by tranformersDeclaration
Swift
open func transform(config: Any) throws -> [OnboardingInfoKey : Any]
Parameters
config
the input config data
Return Value
[OnboardingInfoKey: Any] dictionary of the transformed data where the key is the associated key and the data is the result of the
transformer